The matlab code does not display the graph with Matlab R2015a

2 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 23 Feb 2023
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)');

More Answers (1)

Oguz Kaan Hancioglu
Oguz Kaan Hancioglu on 22 Feb 2023
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 Comments
Mathew Aibinu
Mathew Aibinu on 23 Feb 2023
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.

Sign in to comment.

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!