Error using plot Data must be numeric, datetime, duration or an array convertible to double.

3 次查看(过去 30 天)
>> clear all
>> close all
>> syms s
>> F = (2*s+1)/(s^3 +3*s^2+4*s+2)
F =
(2*s + 1)/(s^3 + 3*s^2 + 4*s + 2)
>> t = [0:0.1:200];
>> f = ilaplace(F)
f =
exp(-t)*(cos(t) + 2*sin(t)) - exp(-t)
>> plot(t,f)
Error using plot
Data must be numeric, datetime, duration or an array
convertible to double.
I'm getting an error for my code and my teacher isn't sure what the issue is. I am able to plot smaller parts of this function but not the whole this. From what I understand from other posts it seems like the issue may be a symbolic variable or how this is defined? Any answers?

采纳的回答

Abolfazl Chaman Motlagh
f is a symbolic expression not a function or vector. you can create a function with this expression, then plot the value of function on your desired points:
syms s t;
F = (2*s+1)/(s^3 +3*s^2+4*s+2);
f = ilaplace(F); %symbolic expression
f = symfun(f,t); %symbolic function with f as it's expression and t as it's input
t = [0:0.1:200];
plot(t,f(t)) % you need to put all t in argument of f cause now it is a function
% Or
% f = f(t);
% plot(t,f);

更多回答(1 个)

Walter Roberson
Walter Roberson 2022-2-8
syms s T
F = (2*s+1)/(s^3 +3*s^2+4*s+2)
F = 
t = 0:0.1:200;
f = ilaplace(F, s, T)
f = 
y = double(subs(f, T, t));
plot(t, y)
title('0:0.1:200')
%or
figure
fplot(f, [0 100], 'meshdensity', 27)
title('fplot[0,10]')
The default meshdensity is 23. If you do not use the option with at least 27 you will get the wrong plot. 26 will get a plot that almost looks right unless you change the ylim.

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by