Why am not getting any graph?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 31 Oct 2022
Edited: Voss
on 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.
More Answers (1)
KSSV
on 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);
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!