I nee to write a code to solve a definite integral. The output format has to be fprintf.
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
%0 to 3 ∫(−x^3 + 3x^2 − 2) dx
syms x
f = -x.^3 + 3.x^2 - 2;
a=0;
b=3;
int(f, a, b);
This is the code i have so far but i keep getting an error. If some one can help me please and thank you. Formatted output must be frprintf.
0 Kommentare
Antworten (2)
Voss
am 13 Mai 2022
Bearbeitet: Voss
am 13 Mai 2022
syms x
% f = -x.^3 + 3.x^2 - 2;
% ^ this . should be *
f = -x.^3 + 3*x^2 - 2;
a=0;
b=3;
output = int(f, a, b)
fprintf('%f',output)
4 Kommentare
Jomar
am 7 Okt. 2022
Sir can you help me to see what is wrong with my code
syms x
y = 0.5*x;
z = int(y, 0, 10);
fprintf('%.2f',z)
it keeps showing error.
Walter Roberson
am 7 Okt. 2022
What error message are you observing? Which MATLAB version are you using?
John D'Errico
am 13 Mai 2022
Bearbeitet: John D'Errico
am 13 Mai 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
syms x
f = -x.^3 + 3*x^2 - 2;
a=0;
b=3;
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Conversion Between Symbolic and Numeric finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!