フィルターのクリア

how to store output values in a matrix for each output variable?

2 ビュー (過去 30 日間)
taher azim
taher azim 2016 年 8 月 5 日
コメント済み: taher azim 2016 年 8 月 7 日
I want to store output values of x1,g(x) etc in a matrix,plz help me out. here's my program:
function SA()
x1=input('\n enter initial value:-');
acc=input('\n enter accuracy:-');
n=input('\n itterations:-');
while (dg(x1)>1)
x1=input('\n enter initial value:-');
end
fprintf('\n n x1 x2 (x2-x1) g(x1) ');
for i=1:1:n
x2=g(x1);
fprintf('\n %d %f %f %f %f',i,x1,x2,abs(x2-x1),g(x1));
if abs(x2-x1)>acc
x1=x2;
else
fprintf('\n root is %f',x2');
break;
end
end
end
function y=g(x)
y=(((x^2)+1)/3);
end
function z=dg(x)
z=((2*x)/3);
end

採用された回答

Konark Kelaiya
Konark Kelaiya 2016 年 8 月 6 日
Initialize another variable say X3 as X3 = []
Then use X3 to store x1 and g(x) values
Modify this portion of code as
X3 = [];
x1=input('\n enter initial value:-');
acc=input('\n enter accuracy:-');
n=input('\n itterations:-');
X3 = [X3 x1];
while (dg(x1)>1)
x1=input('\n enter initial value:-');
X3 = [X3 x1];
end
Then other changes in below portion of Code
if abs(x2-x1)>acc
x1=x2;
X3 = [X3 x1];
else
fprintf('\n root is %f',x2');
X3 = [X3 x2];
break;
end
  1 件のコメント
taher azim
taher azim 2016 年 8 月 7 日
i made changes accordingly but it didn't work.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by