Plotting inverse Laplace transform

I want to find the inverse Laplace transform and then plot the graph. Below 👇 is the code: syms s t %defines s and t as symbolic variables.
a=0.05;
b=0.0045;
c=0.067;
f=0.0508;
g=0.2;
h=0.45;
x=2.71828;
j=232679478;
r=0.742;
k=(h+r);
F =(1-g)*b*a*j*x^(c+f))/s*(s+a*x^c)(s+b*x^f) + (r*a*j*g*b*x^(c+f))/s*(s+k)*(s+a*x^c)(s+b*x^f); %Definition of the Function F(s)
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
f = ilaplace(F); %calculates the inverse Laplace transform of F(s), resulting in f(t).
f_func = matlabFunction(f) %converts the symbolic function f(t) into a regular MATLAB function.
% Define the time vector for plotting
t_vec = 0:0.1:10; % time from 0 to 10
% Plot the inverse Laplace transform
plot(t_vec, f_func(t_vec))
xlabel('Time (t)')
ylabel('f(t)')
title('Inverse Laplace Transform Plot')
grid on
I got this Error message: undefined function code for input argument of type 'cher'a=0.05;b=0.0045;c=0.067;f=0.0508;g=0.2;h=0.45;x=2.71828;j=232679478;r=0.742;k=(h+r);F =(1-g)*b*a*j*x^(c+f))/s*(s+a*x^c)(s+b*x^f) + (r*a*j*g*b*x^(c+f))/s*(s+k)*(s+a*x^c)(s+b*x^f); %Definition of the Function F(s)f = ilaplace(F); %calculates the inverse Laplace transform of F(s), resulting in f(t).f_func = matlabFunction(f) %converts the symbolic function f(t) into a regular MATLAB function.% Define the time vector for plottingt_vec = 0:0.1:10; % time from 0 to 10% Plot the inverse Laplace transformplot(t_vec, f_func(t_vec))xlabel('Time (t)')ylabel('f(t)')title('Inverse Laplace Transform Plot')grid onI got this Error message: undefined function code for input argument of type 'cher'

7 个评论

Hi Sunday,

Could you write out the transfer function F(s) on a piece of paper and take a photo? Later, we can check if it is correctly coded. Of course, you can also verify it yourself.

You have an extra right parenthesis (that I deleted), and two missing operators (that I added as multiplication operators). The ‘f’ expression is a function of the function and its first and second derivative. The function itself appears to be a constant, since its integral is an ascending straight line.
You most likely need to check to be certain that ‘f’ is correct, then try again.
syms s t %defines s and t as symbolic variables.
a=0.05;
b=0.0045;
c=0.067;
f=0.0508;
g=0.2;
h=0.45;
x=2.71828;
j=232679478;
r=0.742;
k=(h+r);
F =(1-g)*b*a*j*x^(c+f)/s*(s+a*x^c)*(s+b*x^f) + (r*a*j*g*b*x^(c+f))/s*(s+k)*(s+a*x^c)*(s+b*x^f); %Definition of the Function F(s)
f = ilaplace(F); %calculates the inverse Laplace transform of F(s), resulting in f(t).
f = vpa(simplify(f, 500), 5)
f = 
f_func = matlabFunction(f) %converts the symbolic function f(t) into a regular MATLAB function.
f_func = function_handle with value:
@(t)dirac(t).*3.35082543967152e+3+dirac(1,t).*5.804570831842721e+4+dirac(2,t).*8.74046132408455e+3+1.456430405094761e+1
% Define the time vector for plotting
t_vec = 0:0.1:10; % time from 0 to 10
% Plot the inverse Laplace transform
plot(t_vec, f_func(t_vec))
xlabel('Time (t)')
ylabel('f(t)')
title('Inverse Laplace Transform Plot')
grid on
figure
fplot(f, [0 10])
xlabel('Time (t)')
ylabel('f(t)')
title('Inverse Laplace Transform Plot')
grid on
figure
fplot(int(f), [0 10])
xlabel('Time (t)')
ylabel('\int{f(t)}')
title('Inverse Laplace Transform Plot')
grid on
.
F =(1-g)*b*a*j*x^(c+f))/s*(s+a*x^c)(s+b*x^f) + (r*a*j*g*b*x^(c+f))/s*(s+k)*(s+a*x^c)(s+b*x^f); %Definition of the Function F(s)
1 0 1 0v 0 v0 v 0 1 0v 0 v 0 v0 v
The number below each ( ) is the number of open brackets "after" the effect of the symbol above it. Here, "v" has been used to represent -1 -- the case where there has been one too many ")"
F =(1-g)*b*a*j*x^(c+f))/s*(s+a*x^c)(s+b*x^f) + (r*a*j*g*b*x^(c+f))/s*(s+k)*(s+a*x^c)(s+b*x^f); %Definition of the Function F(s)
^^ ^^
In MATLAB, the only case in which you can have two adjacent () expressions, is the case where the first one is a table variable dot index. For example,
T.(EXPRESSION)(INDEX)
is valid where EXPRESSION is either a string constant or a character vector or a positive integer.
Other than that exception for table dot indexing, adjacent () expressions are forbidden.
There is absolutely no implied multiplication in MATLAB -- not anywhere . (Including for internal MuPAD symbolic expressions.) . All multiplication must be indicated explicitly, using either the .* operator or the * operator.
Hi @Sunday Aloke, you can click this image button to upload the photo of the Transfer Function, .

@Sam Chak The image is not downloading. No response whenever I click on it

Perhaps you can find a free image hosting website that requires no registration and allows for simple drag-and-drop functionality, such as Imagebam, Imgbb, or Imgur. Then copy and paste the link in your comment.

请先登录,再进行评论。

 采纳的回答

Hi SA
Speculative answer: I don't believe that the function F is a likely candidate for a Laplace transform. What you have is (looking at just the first term)
F = const/s*(s+a*x^c)*(s+b*x^f)
which is actually (by mistake?)
(const/s)*(s+a*x^c)*(s+b*x^f)
i.e. two factors involving s in the numerator. For the inverse transforn, that leads to stuff like the derivative of a delta function. What seems more likely is
const/(s*(s+a*x^c)*(s+b*x^f))
with all the s factors in the denominator. Similarly for the second term.
Both terms have a factor of s in the denominator. If
invLaplace(g(s)/s) = G(t)
then removing the s in the denominator effectively multplies by s and gives the time domain derivative,
invLaplace(g(s)) = dG(t)/dt.
The code below does both cases.
syms s t
a=0.05;
b=0.0045;
c=0.067;
f=0.0508;
g=0.2;
h=0.45;
x=2.71828;
j=232679478;
r=0.742;
k=(h+r);
d1 = (1-g)*b*a*j*x^(c+f)
d2 = r*a*j*g*b*x^(c+f)
F = d1/(s*(s+a*x^c)*(s+b*x^f)) + d2/(s*(s+k)*(s+a*x^c)*(s+b*x^f));
Fs = d1/( (s+a*x^c)*(s+b*x^f)) + d2/( (s+k)*(s+a*x^c)*(s+b*x^f));
f = ilaplace(F);
fs = ilaplace(Fs);
f_fun = matlabFunction(f);
fs_fun = matlabFunction(fs);
% Define the time vector for plotting
tvec = 0:2000; % extend the time
y = f_fun(tvec);
ys = fs_fun(tvec);
% Plot the inverse Laplace transform
figure(1)
plot(tvec,ys)
grid on
xlabel('Time (t)')
ylabel('df(t)/dt')
title('Inverse Laplace Transform Plot')
grid on
figure(2)
plot(tvec,y)
grid on
xlabel('Time (t)')
ylabel('f(t)')
title('Inverse Laplace Transform Plot')
grid on

更多回答(0 个)

类别

产品

版本

R2020a

标签

Community Treasure Hunt

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

Start Hunting!

Translated by