mcarterbrown.com  

General Chat MCB's Coffee House: Pull up a seat, and grab your favorite caffeinated beverage. Non-paintball related chat within.

Reply
 
Thread Tools
Old 11-11-2012, 03:16 PM   #1 (permalink)
Active Member
 
Join Date: Nov 2011

Matlab help

Ok so for my applied math class, we are writing a matlab script to preform finite differencing on a rectangular heat fin to determine the temperature profile of the heat with with distance. Now before anyone says it I know this is much more easily done in solid works but that apparently not the point according to my prof. The heat fin in question can experience 3 boundry conditions on the outside edge of the fin, one its insulated, 2 its at ambient temperature, 3 convection occurs. The below is what I have so far but the values for y and t are a little funky. Any help and explanations would be greatly appreciated.

n=input('type number of intervals: ');
bc=input('Boundary conditions: for an insulated system, type 1. if outer edge is at ambient temperature, type 2. if convection occurs at the outer edge, type 3: ');
tb=298; %temp of base of fin
tsurr=273; %temp of surroundings
k=1; %thermal condctivity
h=1; %heat transfer
thck=1; %thickness of fin
l=1; %length of fin
w=1; %width of fin
m=1;
%values derived from above
a=w*thck; %crosssectional area of fin
dz=l/n; %interval size
p=2*w+2*thck; %perimeter of fin
% initial equation is T''-2hP/ka(T-Ta)=0
% after transform equation becomes y''-(2hpl^2/Ka)y=0
% y = T-Tsurr/Tb-Tsurr, derivatives of y are with respect to z (z=x/l)
alpha=(2*h*p*l*l)/(k*a);
% set y and solution vector sizes. set x matrix size
z=zeros(n);
y=zeros(n,m);
g=zeros(n,m);
x=zeros(n,m);
t=zeros(n,m);
z(1,1)=1;
g(1)=1;
% build matrix between boundaries
for i=2:1:n-1
z(i,i-1)=l/dz^2;
z(i,i)=alpha+2/dz^2;
z(i,i+1)=l/dz^2;
g(i)=0;
end
% establish boundary conditions
for i=n
if bc==1
z(i,i-1)=2/dz^2;
z(i,i)=-alpha-(2/dz^2);
end
if bc==2
z(i,i-1)=0;
z(i,i)=1;
end
if bc==3
z(i,i-1)=2/dz^2;
z(i,i)=-alpha-(2/dz^2)-(2*h*l)/(k*dz);
end
end
% Implement Thomas's Algorithm to solve
for i=2:1:n
z(i,i)= z(i,i)-(z(i,i-1)/z(i-1,i-1))*z(i-1,i);
g(i)=g(i)-(z(i,i-1)/z(i-1,i-1))*g(i-1);
z(i,i-1)=0;
end
y(n)=g(n)/z(n,n);
for i=n-1:-1:1
y(i)=(g(i)-z(i,i+1)*y(i+1))/z(i,i);
end
x(1)=0;
for i=2:1:n+1
x(i)=x(i-1)+dz;
end
dkv23 is offline   Reply With Quote
Old 11-11-2012, 03:29 PM   #2 (permalink)
The Millrat
 
O'Lane's Avatar
 
Join Date: Feb 2007

Haha, I just spent my morning writing matlab code, I've still got a bit to go so I feel your pain... What exactly do you mean by funky y and t values, do you have the equations for which you are trying solve? Also be sure to include the following code at the top of you code...

clc;
clear all;

This will clear any previous calculations done so they don't interfere with your code as it runs.
__________________
Custom Parts Machining... Feel Free to Contact
"All that is necessary for evil to succeed is for good men to do nothing"
God Bless America
O'Lane is offline   Reply With Quote
Old 11-11-2012, 03:45 PM   #3 (permalink)
The Millrat
 
O'Lane's Avatar
 
Join Date: Feb 2007

What is you code supposed to output, when I run it, I enter a number of intervals and a condition (1,2 or 3) and the program runs but I get nothing out of it.
__________________
Custom Parts Machining... Feel Free to Contact
"All that is necessary for evil to succeed is for good men to do nothing"
God Bless America
O'Lane is offline   Reply With Quote
Old 11-11-2012, 04:12 PM   #4 (permalink)
Pronounced Hooper
 
HOEPER's Avatar
 
Join Date: Jan 2010
Location: NoDak

I would give necessary body parts to be fluent in matlab. In half of my classes we're expected to know how to use it even though we've never been taught.
__________________
On the subject of Holy water paintballs:
Quote:
Originally Posted by CrazyRuskii View Post
I can see it now, a mini van full of priests going 80mph through a suburb blasting metallica....


Feedback 2012 Sale WTB Thread
HOEPER is offline   Reply With Quote
Old 11-11-2012, 04:26 PM   #5 (permalink)
The Millrat
 
O'Lane's Avatar
 
Join Date: Feb 2007

Quote:
Originally Posted by HOEPER View Post
I would give necessary body parts to be fluent in matlab. In half of my classes we're expected to know how to use it even though we've never been taught.
My first introduction to matlab was in thermal physics... Professor walked in, handed us an assignment to be done in matlab, my group got tasked with writing a hard disk fluid simulation and none of us had ever seen or used matlab in our lives... since then though, I've become fairly fluent in it and it is very helpful once you get the hang of it.
__________________
Custom Parts Machining... Feel Free to Contact
"All that is necessary for evil to succeed is for good men to do nothing"
God Bless America
O'Lane is offline   Reply With Quote
Old 11-11-2012, 04:37 PM   #6 (permalink)
Active Member
 
Join Date: Nov 2011

By funky i mean the values alternate between a positive and negative values, I am aware of the clear and clc part. The number of intervals could be as small as five and as large as 10k all it does is generate a better approximation. The issue with the alternating values is that the graphs that result when plotted either converge on a value or form a hyperbola, they should however form a some thing similiar to an expential decay. I am attaching a link to a similiar problem that only incorporates the second boundry condition. the example is halfway down in the link.
http://profjrwhite.com/matlab_course...x/fd_intro.pdf
-Duncan
dkv23 is offline   Reply With Quote
Old 11-11-2012, 04:52 PM   #7 (permalink)
The Millrat
 
O'Lane's Avatar
 
Join Date: Feb 2007

Quote:
Originally Posted by dkv23 View Post
By funky i mean the values alternate between a positive and negative values, I am aware of the clear and clc part. The number of intervals could be as small as five and as large as 10k all it does is generate a better approximation. The issue with the alternating values is that the graphs that result when plotted either converge on a value or form a hyperbola, they should however form a some thing similiar to an expential decay. I am attaching a link to a similiar problem that only incorporates the second boundry condition. the example is halfway down in the link.
http://profjrwhite.com/matlab_course...x/fd_intro.pdf
-Duncan
Alright, I think I see what your talking about, I just ran a data set and exported the x and y vectors into excel and plotted them and got the following...



and for further help, writing any kind of code always requires the proper material to assist in programming...

__________________
Custom Parts Machining... Feel Free to Contact
"All that is necessary for evil to succeed is for good men to do nothing"
God Bless America
O'Lane is offline   Reply With Quote
Old 11-11-2012, 04:55 PM   #8 (permalink)
The Millrat
 
O'Lane's Avatar
 
Join Date: Feb 2007

Could you just insert in absolute value command when collecting y value data to fix the issue?

so where ever you calculate y in you code instead of the following...

y = "code";

do

y = abs("code");
__________________
Custom Parts Machining... Feel Free to Contact
"All that is necessary for evil to succeed is for good men to do nothing"
God Bless America
O'Lane is offline   Reply With Quote
Old 11-11-2012, 05:39 PM   #9 (permalink)
Active Member
 
Join Date: Nov 2011

That might jst work, I will try it and let you know. That would make the graph come out correctly but I am not sure what that would ddo for the integrity of the data?
-Duncan

Last edited by dkv23; 11-11-2012 at 05:43 PM.
dkv23 is offline   Reply With Quote
Old 11-11-2012, 05:46 PM   #10 (permalink)
Active Member
 
Join Date: Nov 2011

Ok so my friend and I tried that and it still results in a data set that jumps around whereas it should supposedly result in a nice curve.
-Duncan
dkv23 is offline   Reply With Quote
Reply

  mcarterbrown.com » General » General Chat

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -4. The time now is 07:14 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO
© MCB Network LLC