I nee to write a code to solve a definite integral. The output format has to be fprintf.
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
%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 commentaires
Réponses (2)
Voss
le 13 Mai 2022
Modifié(e) : Voss
le 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 commentaires
Jomar
le 7 Oct 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
le 7 Oct 2022
What error message are you observing? Which MATLAB version are you using?
John D'Errico
le 13 Mai 2022
Modifié(e) : John D'Errico
le 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 commentaires
Voir également
Catégories
En savoir plus sur Conversion Between Symbolic and Numeric dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!