Got a working script, but cannot get the right answer.

Hey. I asked a question yesterday about this script, but I found out how to make it run. Now my problem is, that I only get 1 solution to my system, and I need two solution. The following equations are my system:
2u^2 - 4u + v^2 + 3w^2 + 6w + 2 = 0
u^2 + v^2 - 2v + 2w^2 - 5 = 0
3u^2 - 12u + v^2 + 3w^2 + 8 = 0
Matlab puts following output:
u= 4,6293
v= -2,0049
w= -1,0295
and I need to get:
u = 1,096 and u=2
v = -1,1592 and v= 1
w=-0,26115 and w = -1
This is my script:
% Computer problem % x0 startgæt, k antal iterationer % kald fx. NEWTm([1;1;1],2)
function x=NEWTm(x0,k)
x=x0;
for i=1:k
b=F(x);
s=DF(x)\b;
x=x-s;
end;
end
function y=F(x)
y=zeros(3,1); % 0-punkter i 3x1 matrix
y(1)=2*x(1)^2 - 4*x(1) + x(2)^2 + 3*x(3)^2 + 6*x(3) + 2;
y(2)=x(1)^2 + x(2)^2 - 2*x(2) + 2*x(3)^2 - 5;
y(3)=3*x(1)^2 - 12*x(1) + x(2)^2 + 3*x(3)^2 + 8;
end
function dy=DF(x)
dy=zeros(3,1);
dy(1,1)=4*x(1)-4;
dy(1,2)=2*x(2);
dy(1,3)=6*x(3)+6;
dy(2,1)=2*x(1);
dy(2,2)=2*x(2)-2;
dy(2,3)=4*x(3);
dy(3,3)=6*x(1)-12;
dy(3,2)=2*x(2);
dy(3,3)=6*x(3);
end
Hope anyone can help me.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 12월 3일

0 개 추천

You will need to use a different starting point to find the second solution.

댓글 수: 1

Also, Newton's method may take more than 2 iterations to converge ... you can loop until norm(b) is small enough.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2012년 12월 3일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by