Mesh/Contour Plot of Temperature Distribution

I am attempting to solve the following problem:
x,y spacing=.2
Create a surface and contour plot of temperature distribution from the given data.
Given equations describe heat dist. in a flat square metal plate:
T(x,y)=(T2-T1)*w(x,y)+T1
where w(x,y)=(2pi) * (summation(n is odd, to infinity)((2/n) * sin((n*pi*x)/L)) * (sinh((n*pi*y/L)) / (sinh((n*pi*W)/L))
T1=3 sides held at constant of 70 degrees
T2=4th side held at constant of 200 degrees
W=L=2ft.
This is my current code and dilemma, with my current code the dimensions of x,y,T(temperature) have dimensions that are not compatible to graph using functions such as surf(x,y,t). Any insight or direction is greatly appreciated.
clc;
clear all;
T1=70;T2=200;L=2;W=2;i=0; %givens defined
for x=0:.2:2%for loop for W defined as x
i=i+1;%i increment of growth defined
j=0;%j initial defined
for y=0:.2:2 %for loop for L defined as y
j=j+1;%j increment of growth defined
error=100; Initial error defined
term=10*eps; Initial term defined(attempted to simulation term going to infinity)
n=1;% n initial defined
while abs(error)>.01%while loop defined as absolute value of error >1 percent
termnext=term+(2*pi)*(2/n)*(sin(n*pi*x)/L)*((sinh((n*pi*y)/L))/(sinh((n*pi*W)/L)));%Next term defined from previous term + the given equation.
if abs(error)~=0 %conditional statement revising error value when error ~=0
error=((termnext-term)/term)*100;
n=n+2; %n increment of growth defined as odd by adding 2 each cycle
end
end
end
end
t(x,y)=(T2-T1)*termnext+T1;%Given equation of t defined with substitution of (w(x,y)
surfc(x,y,t)% unsuccessful attempt at plotting x vs y vs t.

 Accepted Answer

surfc(0:.2:2, 0:.2:2, t)

3 Comments

Received error with revised surfc statement:
Error using surf (line 75)
Data dimensions must agree.
Error in surfc (line 56) hs = surf(cax, args{:});
Error in CH5_P35v2 (line 23) surfc(0:.2:2,0:.2:2,t)
In addition, I am not sure if I am using the eps function properly, I have no examples of its usage in my textbook solely a short reference to it. In its current state, 10*eps I receive a NAN in my workspace as t and my termnext, the NAN are eliminated if I change the command to 10+eps...I am not sure if I am pushing in the proper direction but I have not and will not give up!
When x or y are not integers, you cannot store into t(x,y).
xvals = 0 : 0.2 : 2;
yvals = 0 : 0.2 : 2;
for xidx = 1 : length(xvals)
x = xvals(xidx);
for yidx = 1 : length(yvals)
y = yvals(yidx);
......
w(xidx, yidx) = ....
end
end
T = (T2-T1) * w + T1;
surfc(xvals, yvals, T)
Tricky Tricky, thank you so much for your insight, I did not know the integers limitations. It explains why I would get unexpected sizes when viewing my workspace for the variable. This is a pretty strong/cool code!
Thank you!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!