# Plotting Sum of series

100 views (last 30 days)
jan van doorn on 12 Oct 2019
Hi all,
I want to plot the tempersature distribution:
For x = 0.5 (constant) and y =0:0.1:2;
I used the code below which give me an error:
Error using plot
Data must be numeric, datetime, duration or an array convertible to double.
What am I doing wrong?
Thnx
Jan
clear
clc
x = 0.5;
h = 0.1;
ymax = 2;
y = 0:h:ymax;
syms n
T = 273+symsum(400/sinh(2*pi*n)*n*pi*(1-((-1)^n)*cos(1))/((1-(n^2)*(pi^2))^2)*sin(n*pi*x)*sinh(n*pi*y), n, 1, Inf);
plot(T,y);
xlegend("Static Temperature (c)");
ylegend("Position (m)");

Shaun Hamilton on 12 Oct 2019
If you look at the output of T, you can see why you are not getting a plot. I would, plot each of the four answers for T.
jan van doorn on 12 Oct 2019
symsum is defined as
symsum(function, variable, lower boundry, upper boundry)
It is a summation from n=1 to n=Inf over the function mentioned above.

Sulaymon Eshkabilov on 12 Oct 2019
Hi,
In your exercise, it is more appropriate to use numerical solution approach instead of symbolic math. Here is one of the possibe solutions:
x = 0.5;
h = 0.1;
ymax = 2;
y = 0:h:ymax; T(1,:)=273*ones(size(y));
for n=1:5-1
for m = 1:numel(y)
T(n+1,m) = T(n,m)+sum(400/sinh(2*pi*n)*n*pi*(1-((-1)^n)*cos(1))/((1-(n^2)*(pi^2))^2)*sin(n*pi*x)*sinh(n*pi*y(m)));
end
end
%%
plot(y, T);
xlabel("Static Temperature (c)");
ylabel("Position (m)");
Good luck.

Sulaymon Eshkabilov on 13 Oct 2019
Hi,
This exercise is pretty much the same as the previous on, e.g.:
x = 0.5;
h = 0.1;
ymax = 2;
y = 0:h:ymax; T(1,:)=ones(size(y));
for n=1:5-1
for m = 1:numel(y)
T(n+1,m) = T(n,m)+(48/(pi^6))*sum(((-1^n)/(n^3))*((-1^m)-1)/(m^3))*...;
end
end
Good luck.
jan van doorn on 13 Oct 2019
It gives me a 5 x 21 matrix for T. But I expected an array of length: numel(y).
clear
clc
a = 1e-4;
t = 0.1;
x = 0.5;
h = 0.1;
ymax = 2;
y = 0:h:ymax;
T(1,:)=ones(size(y));
for n=1:5-1
for m = 1:numel(y)
T(n+1,m) = T(n,m)+(48/(pi^6))*sum(((-1^n)/(n^3))*((-1^m)-1)/(m^3))*sin(n*pi*x)*sin(m*pi*y(m))*exp(-(n^2+m^2)*pi^2*a*t);
end
end
Sulaymon Eshkabilov on 13 Oct 2019
Hi
From your question, I see that you'd like to set n = 1. If so, the loop will be:
T(1,:)=ones(size(y)); n=1;
for m = 1:numel(y)
T(1,m) = T(n,m)+(48/(pi^6))*sum(((-1^n)/(n^3))*((-1^m)-1)/(m^3))*sin(n*pi*x)*sin(m*pi*y(m))*exp(-(n^2+m^2)*pi^2*a*t);
end
Good luck.

R2019b

### Community Treasure Hunt

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

Start Hunting!