Asked by 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)");

Answer by Sulaymon Eshkabilov
on 12 Oct 2019

Accepted Answer

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

Thanks for your answer, unfortunately it is not working :(

It gives me a 5 x 21 matrix for T. But I expected an array of length: numel(y).

Could you please help me one last time?

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.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Shaun Hamilton (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/484945-plotting-sum-of-series#comment_755515

## jan van doorn (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/484945-plotting-sum-of-series#comment_755519

Sign in to comment.