Create a function to find the product of three numbers, I am trying to use random numbers but an error keeps coming up
2 views (last 30 days)
Show older comments
This is my code i was testing:
function out = rand_Prod (in_a,in_b_,in_c)
in_a = rand()
in_b = rand()
in_c = rand()
rand_Prod = in_a*in_b*in_c
out = rand_Prod);
end
Then this is the error coming up
function out = rand_Prod (in_a,in_b_,in_c)
↑
Error: Function definitions are
not permitted in this context.
2 Comments
Jan
on 10 Nov 2022
This sounds like a homework question. Without mentioning any details and posting in in form of a command, you will not get a solution from this forum. Please solve your homework by your own.
Steven Lord
on 10 Nov 2022
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Answers (1)
Jan
on 10 Nov 2022
Edited: Jan
on 10 Nov 2022
Where did you create this function? This cannot happen in the command window. Open a file using the editor, create the function there and save it as M-file in a folder, which belongs to the Matlab path.
Steven has suggested the Onramp tutorial already. You find such explanations there also.
A note: Defining 3 inputs is not useful, if you overwrite them directly. So either use the inputs, or create the variables internally.
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!