Why am not getting any graph?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Voss
am 31 Okt. 2022
Bearbeitet: Voss
am 31 Okt. 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 Kommentare
Weitere Antworten (1)
KSSV
am 31 Okt. 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);
Siehe auch
Kategorien
Mehr zu Number Theory 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!