Matlab fprintf

Matlab - fprintf 用法(轉(zhuǎn))

%

% 程序作用:

% 計(jì)算并畫出一靜止小球在離地h0的地方以初速度v0做垂直運(yùn)動在t時(shí)刻的位置及速度

%

%定義變量:

% h0? ?--初始高度(m)

% vo? ?--初始速度(m/s)

% g? ? --重力加速度(m/(s^2))

% t? ? --時(shí)間(s)

% ht? ?--t時(shí)刻小球的高度(m)

% vt? ?--t時(shí)刻小球的速度(m/s)

%

%給定初始高度、速度及重力加速度

h0=500;

v0=0;

g=-9.81;

%時(shí)間的變化區(qū)間

t=0:1:10;

%計(jì)算速度

vt=g.*t;

%計(jì)算高度

ht=g.*(t.^2)/2+h0;

%繪圖

plot(t,vt,t,ht);

%輸出數(shù)據(jù)

fprintf('%f s the height is %f m\n',t,ht);

輸出:

2.000000 s the height is 3.000000 m

4.000000 s the height is 5.000000 m

6.000000 s the height is 7.000000 m

8.000000 s the height is 9.000000 m

10.000000 s the height is 500.000000 m

495.095000 s the height is 480.380000 m

455.855000 s the height is 421.520000 m

377.375000 s the height is 323.420000 m

259.655000 s the height is 186.080000 m

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容