回复: bisection methods?
谢谢meteora1005! 谢谢 xiezhh !
不好意思,我的方程没有表达清楚,我现在换一个f(x,y)=x^3+x*y+y^3, 用bisection的方法做出其在[0,2]的图像!
我没有学过符号解法。。。 ezplot , fsolve这些命令也不知道。。。
我想了一下,这样做,但运行出来是个空图。。。
x=zeros(1,200);
y=zeros(1,200); % set x,y to vector
a=0;b=2;
i=1;
for x=0:0.01:2 % given x, get value of y
% try 200 xs, get 200 ys
while (b-a)/2>10^(-12)
c=(a+b)/2;
if x^3+x*c+c^3== 0 %c is a solution, done
break
end
if (x^3+x*c+c^3)*(x^3+x*a+a^3)<0 %a and c make the new interval
b=c;
else %c and b make the new interval
a=c;
end
end
xc=(a+b)/2; %new midpoint is best estimate
y(i)=xc; i=i+1;
end
disp(x);
disp(y);
plot(x,y)
麻烦大家帮我分析一下。。。谢谢!!!
__________________
我才学Matlab,不理解的过程很难过
。大家的任何帮助我都万分感激!
|