Need Help with Newton's Method for the Following code; keep getting errors

1 回表示 (過去 30 日間)
Kevin Hout
Kevin Hout 2016 年 2 月 12 日
編集済み: Walter Roberson 2016 年 2 月 12 日
clc;
close all;
clear all;
x = 1;
y = 2;
for i = 1:10
f(x) = (-x(i).^2) - (2*y(i)) + 2;
f(y) = (-x(i)) - (4*y(i).^2) + 4;
A(1,1) = 2*x(i);
A(1,2) = 2;
A(2,1) = 1;
A(2,2) = 8*y(i);
Z_new = f'\A + f; %f' denotes a column
x(i) = Z_new(1,1);
y(i) = Z_new(1,2);
end
end
  1 件のコメント
KSSV
KSSV 2016 年 2 月 12 日
what is that code? It will not work. x and y are scalars, you are expecting it to be vector inside the loop. You have to read basics of matlab and the problem you are solving.

サインインしてコメントする。

回答 (1 件)

Marc
Marc 2016 年 2 月 12 日
You may want to look into the following in the documentation:
  • @ or annonymous functions
  • preallocation
Cleve Moler's recent blog on Newton's method gives a good example of setting up an anonymous function, its derivative and has a simple implementation of newton's method already there.

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by