フィルターのクリア

Plot an equation in time span T=[0,t]

4 ビュー (過去 30 日間)
Fatemeh Salar
Fatemeh Salar 2022 年 7 月 9 日
編集済み: Karim 2022 年 7 月 9 日
Hi,
I am about to plot an equation but i have 4 variables (including t), how can I plot this equation in domain of 0-T ?
clc
clear
close all
a=input('Please enter a : ')
b=input('Please enter b : ')
c=input('Please enter c : ')
t=input('Please enter t : ')
if(a*b/c>1)
for(0:t)
y=(e^a)*sin(c*t)/sqrt(b);
plot(t,y)
end
elseif(a*b/c<1 && a*b/c>0)
y=sin(a)*sqrt(b*t)/sin(c);
plot(t,y)
elseif(a*b/c<1)
y=cos(a)*e^(b*t)/(c);
plot(t,y)
end
thanks

採用された回答

Karim
Karim 2022 年 7 月 9 日
編集済み: Karim 2022 年 7 月 9 日
You need to create a vector, below you can see a method using the "linspace" function. This creates a vector between 0 and t with 100 elements.
a = 3; % input('Please enter a : ')
b = 2; % input('Please enter b : ')
c = 7; % input('Please enter c : ')
t = 5; % input('Please enter t : ')
% create a vector T between [0 T] with 100 elements
t = linspace(0,t,100);
check = a*b/c;
if check > 1
y = (e^a)*sin(c.*t)./sqrt(b);
elseif check <= 1 && check >= 0
y = sin(a)*sqrt(b.*t)./sin(c);
else % i.e. check < 1
y = cos(a)*e.^(b.*t)./c;
end
figure
plot(t,y)
xlabel('t axis')
ylabel('y values')
grid on
  2 件のコメント
Torsten
Torsten 2022 年 7 月 9 日
You mean
if (a*b/c>1)
y = (e^a)*sin(c.*t)./sqrt(b);
elseif (a*b/c<=1 && a*b/c>=0)
y = sin(a)*sqrt(b.*t)./sin(c);
elseif (a*b/c<0)
y = cos(a)*e.^(b.*t)./c;
end
instead of
if (a*b/c>1)
y = (e^a)*sin(c.*t)./sqrt(b);
elseif (a*b/c<1 && a*b/c>0)
y = sin(a)*sqrt(b.*t)./sin(c);
elseif (a*b/c<1)
y = cos(a)*e.^(b.*t)./c;
end
don't you ?
Fatemeh Salar
Fatemeh Salar 2022 年 7 月 9 日
Yes, I've also forgot to put "." notion since its element-wise operations! Thanks

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

その他の回答 (1 件)

Fatemeh Salar
Fatemeh Salar 2022 年 7 月 9 日
Dear @Karim
Thank you so much.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by