Newton Rhapson for multivariable functions

조회 수: 1 (최근 30일)
curly133
curly133 2018년 10월 17일
편집: curly133 2018년 10월 20일
I am trying to make a program that can solve multivariable equations using the iterative newton rhapson method, but I don't have too much experience in programming or Matlab. This is the formula for the iterative method:
x^(k+1) = x^k - [(f'(x^k))^-1]*f(x^k)
The givens for this are the 2 function f1(x1,x2) and f2(x1,x2) and our initial conditions x1 and x2. Then we have to solve the equations for a certain amount of iterations. x^k, x^(k+1), and f(x^k) are 2x1 matrices. (f'(x^k))^-1 is a 2x2 matrix. Here is what I have so far, but I got stuck with the loop:
%%Newton Rhapson
clear;
clc;
close;
x1 = 0; %initial values (given)
x2 = 1;
initial = (x1,x2);
I = transpose(initial);
f1 = 2x1^2 + x2 - 8; %function 1
f2 = x1^2 - x2^2 + x1*x2 - 4; %function 2
A = (f1,f2)
fx = A.' % transopose of A to give f(x)
df1 = diff(f1,x1); %differentiates f1 wrt x1)
df2 = diff(f1,x2);
df3 = diff(f2,x1);
df4 = diff(f2,x2);
df = [df1,df2;df3,df4]; %2x2 Matrix with differentials
for i = 1:4
y = initial - inv(df)*fx
  댓글 수: 4
Torsten
Torsten 2018년 10월 19일
No, "diff" in this case must be applied to a symbolic expression to get the Jacobian.
Try to turn a symbolic "df" into a function handle via "matlabFunction" and continue with pure numerical calculations within the loop.
Best wishes
Torsten.
curly133
curly133 2018년 10월 20일
How do I do this exactly?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by