Newton Rhapson for multivariable functions

3 ビュー (過去 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 Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by