Graphing problem

2 ビュー (過去 30 日間)
Courtney
Courtney 2011 年 12 月 2 日
I can plot the individual point, but how do I plot the function in the script file. I am having a problem with the sequential numbers updating the temperature so it plots on with individual points not the vector t(0:1:40)
script <a>file:(yes</a> it must be a script file)
a=0.138*10^-6; x=0.5; step=8.64*10^4; t = [0:1:40]; fprintf(' Days Temperature(C) @ 0.5m\n') for t=0:1:40 ts=t.*step; Temp=(2/sqrt(pi))*quadv(inline('exp(-1*u.^2)'),0, (x./(2*sqrt(a*ts))));
Temp5=-15+(12+15)*Temp; t2=[ts/step]; values = [t2(:,1);Temp5(:,1)]; Temp(1)=0; fprintf(' %2d %13.2f\n',values); hold on end plot(t2(:,1),Temp5(:,1));

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 12 月 2 日
a=0.138*10^-6;
x=0.5;
step=8.64*10^4;
t = 0:1:40;
%fprintf(' Days Temperature(C) @ 0.5m\n')
ts=t.*step;
Temp=2/sqrt(pi)*cell2mat(...
arrayfun(@(x1)quadv(@(u)exp(-1*u.^2)',0, x./(2*sqrt(a*x1))),ts,'un',0));
Temp5=-15+(12+15)*Temp;plot(t,Temp5);

その他の回答 (1 件)

Junaid
Junaid 2011 年 12 月 2 日
Dear Courtney,
Whenever you copy code please make it proper so that reader can read and then execute if needed.
something like this...
a=0.138*10^-6; x=0.5; step=8.64*10^4; t = [0:1:40];
fprintf(' Days Temperature(C) @ 0.5m\n')
for t=0:1:40
ts=t.*step; Temp=(2/sqrt(pi))*quadv(inline('exp(-1*u.^2)'),0, (x./(2*sqrt(a*ts))));
Temp5=-15+(12+15)*Temp; t2=[ts/step]; values = [t2(:,1);Temp5(:,1)]; Temp(1)=0; fprintf(' %2d %13.2f\n',values); hold on
end
plot(t2(:,1),Temp5(:,1));
Your code is logically incorrect. At the end you don't have t2 as vector but a scalar number. Try to update the value correctly.
ex. t2(t) = ts/step;

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by