Why am not getting any graph?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
clc;
clear;
syms p;
x = 13.61015;
y = 13257;
a = 5.14;
b = 11.47;
err1 = 0.000001;
f = (x^3 + p^2*x^2 - 10)*sin(x) - y == 0;
i=0;
if ((x^3 + a^2*x^2 - 10)*sin(x) - y) * ((x^3 + b^2*x^2 - 10)*sin(x) - y) > 0
disp ('Wrong Interval');
return
else
c = (a+b)/2;
err = abs(a-b);
end
while err > err1
if ((x^3 + a^2*x^2 - 10)*sin(x) - y) * ((x^3 + c^2*x^2 - 10)*sin(x) - y) < 0
b=c;
i=i+1;
else
a=c;
end
c = (a+b)/2;
err = abs(c-b);
root = c;
end
y1 = (x^3 + c^2*x^2 - 10)*sin(x);
x1 = 0:20;
figure
plot(x1,y1);
disp (i);
disp (c);
disp (err);
0 commentaires
Réponse acceptée
Voss
le 31 Oct 2022
Modifié(e) : Voss
le 31 Oct 2022
Do you mean for y1 to be calculated from x1, rather than from x?
x1 = 0:20;
y1 = (x1.^3 + c^2*x1.^2 - 10).*sin(x1);
To answer your question: you don't see a plot because y1 is a scalar, which happens because x is a scalar. A plot of a single point with no data marker cannot be seen.
2 commentaires
Plus de réponses (1)
KSSV
le 31 Oct 2022
clc; clear all ;
clc;
clear;
syms p;
x = 13.61015;
y = 13257;
a = 5.14;
b = 11.47;
err1 = 0.000001;
f = (x^3 + p^2*x^2 - 10)*sin(x) - y == 0;
i=0;
if ((x^3 + a^2*x^2 - 10)*sin(x) - y) * ((x^3 + b^2*x^2 - 10)*sin(x) - y) > 0
disp ('Wrong Interval');
return
else
c = (a+b)/2;
err = abs(a-b);
end
while err > err1
if ((x^3 + a^2*x^2 - 10)*sin(x) - y) * ((x^3 + c^2*x^2 - 10)*sin(x) - y) < 0
b=c;
i=i+1;
else
a=c;
end
c = (a+b)/2;
err = abs(c-b);
root = c;
end
x1 = 0:20;
y1 = (x1.^3 + c^2*x.^2 - 10).*sin(x1);
figure
plot(x1,y1);
disp (i);
disp (c);
disp (err);
Voir également
Catégories
En savoir plus sur Number Theory 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!