I nee to write a code to solve a definite integral. The output format has to be fprintf.
1 view (last 30 days)
John D'Errico on 13 May 2022
Edited: John D'Errico on 13 May 2022
Do you understand that MATLAB REQUIRES a multiplication operator? You cannot just put a number next to a letter, and expect MATLAB to know this is multiplication. So this is not valid code. Did you read the error message? It tells you that.
f = -x.^3 + 3.x^2 - 2;
Fixing that problem, we have
f = -x.^3 + 3*x^2 - 2;
Next, you need to assign the result of the integration to something.
res = int(f, a, b)
You now need to turn that symbolic variable into a double.
Dres = double(res)
Now use fprintf. Read the help for fprintf.