I need help plotting this inverse Laplace Transform

조회 수: 11 (최근 30일)
Caleb Truscott
Caleb Truscott 2022년 1월 12일
편집: Caleb Truscott 2022년 1월 13일
I am trying to plot an inverse Laplace transform of a function but I keep getting the error "Error using plot. Data must be numeric, datetime, duration or an array convertible to double."
Below is my code:
m=1;
c=6;
k=6;
G = 100.*65.*9.81;
syms s pi t
f1=(1/((s^2+4*pi^2)*(m*s^2+c*s+k))); %first term
pf1=partfrac(f1,s);
f2=(1/(3*(s^2+(6*pi)^2)*(m*s^2+c*s+k))); %second term
pf2=partfrac(f2,s);
f3=(1/(5*(s^2+(10*pi)^2)*(m*s^2+c*s+k))); %third term
pf3=partfrac(f3,s);
f4=(1/(7*(s^2+(14*pi)^2)*(m*s^2+c*s+k))); %fourth term
pf4=partfrac(f4,s);
LF1=ilaplace(f1) %inverse laplace transform of first term
LF1 = 
LF2=ilaplace(f2) %inverse laplace transform of second term
LF2 = 
LF3=ilaplace(f3) %inverse laplace transform of third term
LF3 = 
LF4=ilaplace(f4) %inverse laplace transform of fourth term
LF4 = 
t = [0;0.1;10];
Xss = LF1 - LF2 + LF3 - LF4;
plot(t,Xss)
Error using plot
Data must be numeric, datetime, duration or an array convertible to double.
  댓글 수: 3
Caleb Truscott
Caleb Truscott 2022년 1월 12일
편집: Caleb Truscott 2022년 1월 12일
Hi, I tried this but I get:
m=1;
c=6;
k=6;
G = 100.*65.*9.81;
syms s pi t
f1=(1/((s^2+4*pi^2)*(m*s^2+c*s+k))); %first term
pf1=partfrac(f1,s);
f2=(1/(3*(s^2+(6*pi)^2)*(m*s^2+c*s+k))); %second term
pf2=partfrac(f2,s);
f3=(1/(5*(s^2+(10*pi)^2)*(m*s^2+c*s+k))); %third term
pf3=partfrac(f3,s);
f4=(1/(7*(s^2+(14*pi)^2)*(m*s^2+c*s+k))); %fourth term
pf4=partfrac(f4,s);
LF1=ilaplace(f1) %inverse laplace transform of first term
LF1 = 
LF2=ilaplace(f2) %inverse laplace transform of second term
LF2 = 
LF3=ilaplace(f3) %inverse laplace transform of third term
LF3 = 
LF4=ilaplace(f4) %inverse laplace transform of fourth term
LF4 = 
t = 0:0.1:10;
Xss = LF1 - LF2 + LF3 - LF4;
t_num = 0:0.1:10;
Xss_num = subs(Xss,t,t_num);
Error using sym/subs>normalize (line 239)
Entries in second argument must be scalar.

Error in sym/subs>mupadsubs (line 165)
[X2,Y2,symX,symY] = normalize(X,Y); %#ok

Error in sym/subs (line 153)
G = mupadsubs(F,X,Y);
plot(t_num,Xss_num)
Paul
Paul 2022년 1월 12일
편집: Paul 2022년 1월 12일
Don't use a sym variable name pi. Better is to use a sym constant, i.e., replace all uses of pi with
Pi = sym(pi);
comment out this line:
% t = 0:.1:10

댓글을 달려면 로그인하십시오.

채택된 답변

Paul
Paul 2022년 1월 12일
Replace all instances of pi with Pi, defined as
Pi = sym(pi);
which is a good habit to get into regardless.
Then you can stay in the sym world if you want and use fplot()
fplot(Xss,[0 10])
  댓글 수: 1
Caleb Truscott
Caleb Truscott 2022년 1월 13일
편집: Caleb Truscott 2022년 1월 13일
Hi thank you it works:
m=1;
c=6;
k=6;
G = 100.*65.*9.81;
Pi = sym(pi);
syms s pi t
f1=(1/((s^2+4*Pi^2)*(m*s^2+c*s+k))); %first term
pf1=partfrac(f1,s);
f2=(1/(3*(s^2+(6*Pi)^2)*(m*s^2+c*s+k))); %second term
pf2=partfrac(f2,s);
f3=(1/(5*(s^2+(10*Pi)^2)*(m*s^2+c*s+k))); %third term
pf3=partfrac(f3,s);
f4=(1/(7*(s^2+(14*Pi)^2)*(m*s^2+c*s+k))); %fourth term
pf4=partfrac(f4,s);
x1=ilaplace(f1) %inverse laplace transform of first term
x1 = 
x2=ilaplace(f2) %inverse laplace transform of second term
x2 = 
x3=ilaplace(f3) %inverse laplace transform of third term
x3 = 
x4=ilaplace(f4) %inverse laplace transform of fourth term
x4 = 
%t = 0:0.1:10
Xss = x1 - x2 + x3 - x4;
fplot(Xss,[0 10])
xlabel('Time (s)')
ylabel('x (m)')
legend('Xss(t)')
title('Lateral Displacement')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by