Mesh/Contour Plot of Temperature Distribution

2 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2013-11-11
surfc(0:.2:2, 0:.2:2, t)
  3 个评论
Walter Roberson
Walter Roberson 2013-11-11
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)
Jeremiah
Jeremiah 2013-11-11
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by