how do you make the results of a loop into table?

2 ビュー (過去 30 日間)
rick arellaga
rick arellaga 2015 年 12 月 18 日
編集済み: Walter Roberson 2015 年 12 月 19 日
here is my code
%start
syms 'x';
%to be able to input x
fun= input ('Enter function in terms of "x":');
%user input
f=inline(fun);
z=diff(f(x));
%differentiate in terms of x
f1=inline(z);
xo=input('enter initial value "xo":');
%input user initial value
x=xo;
for i=0:1000
y=x;
x=y-(f(x)/f1(x)) ;
if x==y
break
end
end
%loop
disp(['Root: ',num2str(x), ] );
disp('In the beginning, God said that the four dimensional divergence of an antisymmetric second rank tensor equals zero and there was light.');
%output up to 7 decimal places
m=input('Do you want to continue, Y/N [Y]:','s');
if m=='Y'
clc
newtonrap
else
clc
end
%ask to exit or continue
so, I want to take the answers of 'x','y',f(x) and f1(x) within the loop an make a table out of it. is that possible?
  3 件のコメント
rick arellaga
rick arellaga 2015 年 12 月 19 日
sorry dude i am new to this
now here is my code
if true
%start
syms 'x';
%to be able to input x
fun= input ('Enter function in terms of "x":');
%user input
f=inline(fun);
z=diff(f(x));
%differentiate in terms of x
f1=inline(z);
xo=input('enter initial value "xo":');
%input user initial value
x=xo;
disp(' f(x) f!(x) f(x)/f!(x) x')
disp('======== ======== ========= =========')
for i=0:250
fprintf('%8f %8f %8f %8f\n',f(x),f1(x),b,x)
y=x;
b=(f(x)/f1(x));
x=y-b;
if x==y
break
end
end
%loop
disp(['Root: ',num2str(x,8), ] );
% code
but now im getting the error using fprintf after i restarted matlab
end
Image Analyst
Image Analyst 2015 年 12 月 19 日
I don't see any table - that is a very specific special kind of variable. Looks like you're just printing a table to the command line without using a "table" variable. You forgot to give us the inputs you entered into this program. I, for one, will wait until you give us that.

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

回答 (1 件)

Renato Agurto
Renato Agurto 2015 年 12 月 18 日
Like Jan wrote, you should format your code and explain "table" in order to geta better answer. I only can guess you want a 2D-array:
Before the for loop:
your_table = zeros(1001,4)
in the for loop:
your_table(i,:) = [x y f(x) f1(x)];

カテゴリ

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