I try to run a for loop to plot the function y(t) for 0.1<=t<=0.9 for 5 diffrent t. Can you help me with my code?

4 ビュー (過去 30 日間)
x=-10:0.01:10 ;
y=zeros(5,length(x))
for t=1:2:9
y(t)=((exp((-t*0.1).*x))./(sqrt(1-(t*0.1)^2))).*sin(x.*sqrt(1-(t*0.1)^2)+acos(t*0.1))
end

採用された回答

Les Beckham
Les Beckham 2022 年 3 月 31 日
編集済み: Les Beckham 2022 年 3 月 31 日
You were pretty close. I had to change the loop to loop over the elements of t and save y one row at a time using y(i,:) using one element of t using t(i).
Hopefully this is what you wanted.
x = -10:0.01:10;
t = 1:2:9;
y = zeros(numel(t), numel(x));
leg_strings = {};
for i = 1:numel(t)
y(i,:) = ((exp((-t(i)*0.1).*x)) ./ (sqrt(1-(t(i)*0.1)^2))) .* sin(x.*sqrt(1-(t(i)*0.1)^2) + acos(t(i)*0.1));
leg_strings(i) = {sprintf('t = %d', t(i))};
end
plot(x,y)
grid on
legend(leg_strings)
Note that you could also define t = 0.1:0.2:0.9 and remove the *0.1 from the equation for y.
  3 件のコメント
ON
ON 2022 年 3 月 31 日
yes, I just did that and it works perfectly.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by