Help Print Command Error

function [dy] = y(n,to,t,y0)
t=[0:0.01:5] h=[0.1 0.001] t0=0 y0=1 n=50 h=0.1 t=t0 y=y0
Hello, i'm new to matlab and have developed the following code for a euler solver. for i=1:n k=2-exp(-4*t)-2*y y=y+h*k t=t+h
print('t','y')
end
I'm trying to use the print command but am getting the following error.
Error using inputcheck (line 40) Multiple inputs that look like filenames: 't' and 'y'
Error in print (line 163) [pj, devices, options ] = inputcheck( pj, inputargs{:} );
Error in bmes511_hw3 (line 18) print('t','y')
Any ideas why?

3 件のコメント

Kyle
Kyle 2014 年 2 月 7 日
oops. here's what the function should look like
function [dy] = y(n,to,t,y0)
t=[0:0.01:5] h=[0.1 0.001] t0=0 y0=1 n=50 h=0.1 t=t0 y=y0 for i=1:n k=2-exp(-4*t)-2*y y=y+h*k t=t+h
print('t','y')
end
Mischa Kim
Mischa Kim 2014 年 2 月 7 日
Do you simply want to display the variables in the command window? The print command is used to print a figure.
Kyle
Kyle 2014 年 2 月 7 日
oh... yeah. thats what i'm trying to do.

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

回答 (1 件)

Mischa Kim
Mischa Kim 2014 年 2 月 7 日
編集済み: Mischa Kim 2014 年 2 月 7 日

0 投票

OK. Use
sprintf('%5.2f: %5.2f', t, y)
or something like that. With the %5.2f you can specify the number format: total of five digits, two after the decimal point, fixed-point. Check out the documentation for a full description of the formatting syntax.

1 件のコメント

Mischa Kim
Mischa Kim 2014 年 2 月 7 日
Careful, I just looked at your code. You first define t as a vector, then you re-assign it into a scalar by t = t0.

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

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

タグ

質問済み:

2014 年 2 月 7 日

コメント済み:

2014 年 2 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by