Why am not getting any graph?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Voss
2022년 10월 31일
편집: Voss
2022년 10월 31일
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.
추가 답변 (1개)
KSSV
2022년 10월 31일
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);
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!