Table of values from output

2 ビュー (過去 30 日間)
Umar Naseef
Umar Naseef 2021 年 3 月 28 日
コメント済み: Star Strider 2021 年 3 月 28 日
Hi, I would like help to add a table of output values of x and y values for this code
x0 = [3; -1.5];
maxIter = 50;
tolX = 1e-14;
x = x0;
xold = x0;
for i = 1:maxIter
[f,j] = newtraph(x);
x = x- j\f;
err(:,i) = abs(x-xold);
xold = x;
if (err(:,i)<tolX)
break;
end
end
display(x)
fprintf('Number of iterations: %d \n',i)
function [fval,jac] = newtraph(X)
x = X(1);
y = X(2);
fval(1,1)=x+exp(-x)+y^3;
fval(2,1)=x^2+2*x*y-y^2+tan(x);
jac = [1-exp(-x), 3*y^2;
2*x+2*y+1+(tan(x))^2, 2*x-2*y];
end

採用された回答

Star Strider
Star Strider 2021 年 3 月 28 日
Perhaps something like this:
xv = nan(MaxIter,1);
yv = xv;
for i = 1:maxIter
[f,j] = newtraph(x);
x = x- j\f;
err(:,i) = abs(x-xold);
xold = x;
if (err(:,i)<tolX)
break;
end
xv(i) = x(1);
yv(i) = x(2);
end
OutputValues = table(xv(~isnan(xv)), yv(~isnan(yv)), 'VariableNames',{'X','Y'})
.
  4 件のコメント
Umar Naseef
Umar Naseef 2021 年 3 月 28 日
It works and I cannot thank you enough for this!!!
Star Strider
Star Strider 2021 年 3 月 28 日
As always, my pleasure!
I cannot thank you enough for this!!!
By Accepting my Answer, you already did! Thank you!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by