登录论坛

查看完整版本 : bisection methods?


木心
2008-10-02, 07:35
请问怎么求出 y在 y^5+cosxy^4+y+x=0 中的解

我只知道怎么求简单的显函数的,用 inline 定义
然后 。。。 c = (a + b)/2;
if ( f(c) == 0 )
break;
elseif ( f(a)*f(c) < 0 )
b = c;
else
a = c;
等等.....

但这个就不会了。。请问应该怎么做。

谢谢!

meteora1005
2008-10-02, 16:38
你再把cosxy^4这句写明白点,是cosx*y^4还是什么,你想得到一个用x表示y的表达式就得用符号解法,对这个方程可能不太好解啊,根据我的知识是很难解出来的。要是数值解就好办了。:confused:

木心
2008-10-02, 21:30
是 cosx*y^4. 那请问用数值解怎么解? 谢谢!!!

xiezhh
2008-10-03, 08:12
你上面的解释还是不清楚,是cos(x)*(y^4)还是cos(x*y^4),我当成cos(x)*(y^4),可以采用隐函数画图: ezplot('y^5+cos(x)*y^4+y+x=0',[-10 10])
利用图解法,从图上可以看出x固定时的y值

也可以通过下面命令求数值解,求出的解跟初值有关。
[xy,fval]=fsolve('x(2)^5+cos(x(1))*x(2)^4+x(2)+x(1)',[1 1])

meteora1005
2008-10-03, 10:44
楼主好像不是这个意思啊,他想得到的是符号解,这个方程数值解没什么意义吧,怎么能求出符号解啊?

木心
2008-10-03, 12:07
谢谢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)

麻烦大家帮我分析一下。。。谢谢!!!

meteora1005
2008-10-03, 13:30
如果你只想画图的话就好办了:ezplot('x^3+x*y+y^3=0',[0 2 0 -2])

木心
2008-10-03, 13:51
谢谢!但是老师只想让我们运用bisection 的方法做图。。。。
我不知道我的程序哪里错了。。。

meteora1005
2008-10-03, 19:45
在两个disp前加一句x=0:0.01:2;还有你在检查一下xc的计算过程,怎么每次循环后的值都是2,画出的图是错的。

木心
2008-10-03, 23:28
谢谢!
我觉得现在的问题是怎么把 y 和 x 一一对应??

a=0;b=2;


for x=0:0.01:2 % given x, get value of y
% try 200 x, get 200 y
while (b-a)/2>10^(-12)
c=(a+b)/2;

if (x^3+x*c+c^3)*(x^3+x*c+c^3)== 0 , %c is a solution, done
break;
end
if (x^3+x*c+c^3)*(x^3+x*c+c^3)<0 %a and c make the new interval
b=c;
else %c and b make the new interval
a=c;
end
end

d=(a+b)/2; %new midpoint is best estimate

y=d;
disp(x);
disp('y=');
disp(y);
end

x=0:0.01:2
plot(x,y);

meteora1005
2008-10-03, 23:45
你的y算出来都是2啊,肯定哪错了,我不太懂bisection的原理,还是自己好好检查一下

木心
2008-10-04, 01:27
好像图做出来了...但结果好像有点乱...我再查一遍...
谢谢:)

y=zeros(1,200);
i=1;
for x=0:0.01:2
a=-2;b=2; % try 200 x, get 200 y
while (b-a)/2>10^(-12)
c=(a+b)/2;

if (x^3+x*a+a^3)*(x^3+x*c+c^3)== 0 , %c is a solution, done
break;
end
if (x^3+x*a+a^3)*(x^3+x*c+c^3)<0 %a and c make the new interval
b=c;
else %c and b make the new interval
a=c;
end
end

y(i)=(a+b)/2; %new midpoint is best estimate
i=i+1;
disp('x=');
disp (x);

disp('y=');
disp (y) ;
end
x=0:0.01:2
plot(x,y)

meteora1005
2008-10-04, 13:01
我看图已经画对了啊,基本成功了:biggrin: