Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider a user-defined function, which takes 3 scalar input values. The functio

ID: 3775759 • Letter: C

Question

Consider a user-defined function, which takes 3 scalar input values. The function file returns I scalar output, which is calculated as the first value multiplied by the second value plus the third value. For example, entering 2, 3, and 4, will result in the value of 10 being returned to the command window (because 2 times 3 + 4 = 10). In the box below, write a MATLAB function file, named myfile .m, using the following variable names: in1, in2, in3, and out. How would you type at the command prompt to get the response shown in the command window below? Note that this interaction corresponds to the numerical example described above. >> output = 10 Submission: 1 function m-file, printout of your command window.

Explanation / Answer

function out = myfun(in1,in2,in3) %creatig a function with 3 inputs and one output

out = in1*in2+in3; %calculating output value

end

input and output from command window:

>> myfun(3,2,4)           %calling user function from command window

ans =

    10                          %function result to the command window

>>

>> myfun(2,3,4)

ans =

    10

>> myfun(5,6,2)

ans =

    32

>>