The matlab code does not display the graph with Matlab R2015a

2 次查看(过去 30 天)
clear all; close all;
syms k t
I_0=1; mu=1.5; lambda=0.3; gamma=0.1;
t=0:1:20;
y=I_0*symsum((-lambda *t.^(mu)).^k/(2.^((k*(k-1)*mu)/2)*factorial(k* mu)),k,[0, Inf]) + gamma*symsum(((-lambda).^(k-1)*(t.^(k*mu)))/(2.^((k*(k-1)*mu)/2)*factorial(k* mu)),k,[1 Inf]);
plot(t,y,'-+');
grid on
xlabel('time t');
ylabel('I(t)');
The graph is not displayed with Matlab R2015a

采纳的回答

Walter Roberson
Walter Roberson 2023-2-23
If I recall correctly, back in R2015a, fplot did not yet apply to symbolic expressions.
That symsum() to infinity does not find a closed form solution so it leaves it as a symsum. If you use matlabFunction() on the result, then it leaves it in terms of symsum(), which is not a good thing as symsum is not defined for numeric parameters. You can attempt to fplot() the resulting handle, but it takes too long for any practical purposes. If you substitute in specific t values and run the symsum with those, it takes too long for any practical purposes.
I think for practical purposes you are going to need to truncate the infinite sums.
You also have the problem that you have factorial(k*mu) but mu = 1.5 so for odd integers k*mu is non-integral which is a problem for factorial. You have to switch to gamma.
TERMS = 30;
syms k t
I_0=1; mu=1.5; lambda=0.3; Gamma=0.1;
t=0:1:20;
inner1 = (-lambda *t.^(mu)).^k./(2.^((k*(k-1)*mu)/2).*gamma(k*mu+1));
inner2 = ((-lambda).^(k-1).*(t.^(k*mu)))./(2.^((k*(k-1)*mu)/2).*gamma(k*mu+1));
inner1sum = symsum(inner1, k, [0, TERMS]);
inner2sum = symsum(inner2, k, [1, TERMS]); %notice different bounds
y = I_0 * inner1sum + Gamma * inner2sum;
Y = double(y);
plot(t, Y)
grid on
xlabel('time t');
ylabel('I(t)');

更多回答(1 个)

Oguz Kaan Hancioglu
Keep your t variable in symbolic and use fplot to plot the symbolic function.
Bests
clear all; close all;
syms k t
I_0=1; mu=1.5; lambda=0.3; gamma=0.1;
%t=0:1:20;
y=I_0*symsum((-lambda *t.^(mu)).^k/(2.^((k*(k-1)*mu)/2)*factorial(k* mu)),k,[0, Inf]) + gamma*symsum(((-lambda).^(k-1)*(t.^(k*mu)))/(2.^((k*(k-1)*mu)/2)*factorial(k* mu)),k,[1 Inf]);
fplot(y,[0,20]);
grid on
xlabel('time t');
ylabel('I(t)');
  2 个评论
Mathew Aibinu
Mathew Aibinu 2023-2-23
The graph is still not displayed. Here is result when I ran the code:
Error using fcnchk (line 106)
If FUN is a MATLAB object, it must have an feval method.
Error in fplot (line 60)
fun = fcnchk(fun);
Error in AAM24 (line 6)
fplot(y,[0,20]);
Kindly note that AAM24 is the name with which the file is saved.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品


版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by