PDA

View Full Version : Matlab help



Deathslayer7
2011-12-05, 11:21 PM
I need help integrating a nasty function. It is something like this. Anything in bold is my opinion and not part of the code. Please note that while y is not defined yet, it will be later on, which is why I currently have it in there.

Define Variables:

L = 0.075; % length [m]
W = 0.015; % width [m]
d = 0.003; % nodal spacing [m]
Tb = 393; % base temperature [K]
Tamb = 293; % ambient air temperature [K]
k = 177; % thermal conductivity [W/m-K]
h = 650; % heat transfer coefficient [W/m^2-K]
q = 250; % theraml radiation flux W/m^2
N = 10000; % iteration


Use of for loops.

Code:

for x=0:.001:.075
for y=0:.001:.015
for n=1:100

alpha=n*pi()/(2*L); %hint given by our instructor. no idea how he got it
lambda=n*pi()/L; %hint given by our instructor. no idea how he got it
k1=h/(alpha*k);

T(x,y)=(Tb-Tamb)*sum(int(k1*sin(alpha*x)+cos(alpha*x),x,0,W))

end
end
end


I get this:

??? Undefined function or method 'int' for input arguments of type 'double'.

Error in ==> ME_315_Project_David_Fyda at 171
T(x,y)=(Tb-Tamb)*sum(int(k1*sin(alpha*x)+cos(alpha*x),x,0,W))


Now this is what I NEED to do. And I'm not sure if I am on the right track.

I need to do a summation from 1 to infinity of the integral of that function. Please note that this is only the beginning part of the equation, and I think that if i can get this part, I can do the rest.

Mando Knight
2011-12-05, 11:33 PM
You need to define x as a symbolic scalar to use that function (http://www.mathworks.com/help/toolbox/symbolic/int-integral.html) that way.

Lambda and alpha look like angles in radians. Not sure what they represent since I don't entirely know what you're doing with them.

Deathslayer7
2011-12-05, 11:44 PM
but x isn't symbolic. It is defined. So I guess I should use a different variable then.

Deathslayer7
2011-12-05, 11:45 PM
The Code:
L = 0.075; % length [m]
W = 0.015; % width [m]
d = 0.003; % nodal spacing [m]
Tb = 393; % base temperature [K]
Tamb = 293; % ambient air temperature [K]
k = 177; % thermal conductivity [W/m-K]
h = 650; % heat transfer coefficient [W/m^2-K]
q = 250; % theraml radiation flux W/m^2
N = 10000; % iteration

syms x1

for x=0:.001:.075
for y=0:.001:.015
for n=1:100

alpha=n*pi()/(2*L);
lambda=n*pi()/L;
k1=h/(alpha*k)

T(x,y)=(Tb-Tamb)*sum(int(k1*sin(alpha*x1)+cos(alpha*x1),x1,0, W))
end
end
end


The Error:

??? Error using ==> sym.sym>checkindex at 2729
Index must be a positive integer or logical.

Error in ==> sym.sym>privformatscalar at 2679
checkindex(x);

Error in ==> sym.sym>privformat at 2663
s = privformatscalar(x);

Error in ==> sym.sym>sym.subsasgn at 1433
[inds{k},refs{k}] = privformat(inds{k});

Error in ==> ME_315_Project_David_Fyda at 171
T(x,y)=(Tb-Tamb)*sum(int(k1*sin(alpha*x1)+cos(alpha*x1),x1,0, W))

Mando Knight
2011-12-06, 12:09 AM
...I'm not sure what the error output is saying, but it looks to me like your summation isn't logical. I can't really make heads or tails of what your equation is really trying to do right now. Is there a way you could present a "normal" symbolic form of what you're trying to do? What part goes from one to infinity? What is the summation supposed to do?

Deathslayer7
2011-12-06, 12:12 AM
This is what I need in mathematical form:

T(x,y)= T_amb+(T_b-T_amb)*the summation of n from 1 to infiinity of {the integral from zero to W of [h/(alpha_sub_n*k)*sin(alpha_sub_n*x)+cos(alpha_sub_n *x)]dx}

edit: where

alpha_sub_n=n*pi/(2*L)

OR in other terms

I need this:

T(x,y)= T_amb+(T_b-T_amb)*the summation of n from 1 to infiinity of {the integral from zero to W of [(2*h*L)/(n*pi*k)*sin(n*pi*x/(2*L)+cos(n*pi*x/(2*L)]dx}

Mando Knight
2011-12-06, 12:39 AM
...Alright, then what's the (x,y) part? It's not a function of x & y, since x is the variable of integration...

Excluding that, your right hand side should, in the end, look something like this in pseudocode...

Ta + (Tb-Ta) * sum(f(n), n, 1, inf)

Where f(n) is your gnarly integral, which has an analytical answer in terms of n.

Now, the sum() function doesn't work like that, I don't think, so you're going to have to get a little creative (or, rather, get back to the utter basics)...

for n:1:N (you are NOT going to sum to infinity. This thing should converge, but if it doesn't, the assignment's pointless.)
S = S + f(n)
end

Then take S, which is your sum.

Deathslayer7
2011-12-06, 12:44 AM
I only posted the first part of the function, so yes in this case it is a function of x. But this thing is a terrible evil function and I do not want to write it out. Because even if I did write it out, no one could understand it. Trust me on that.

I'll try the pseudocode and get back to you. And I realize that summing to inf is pointless, so a number like 100 or even 1000 would work well enough.

Deathslayer7
2011-12-06, 12:55 AM
Code:

L = 0.075; % length [m]
W = 0.015; % width [m]
d = 0.003; % nodal spacing [m]
Tb = 393; % base temperature [K]
Tamb = 293; % ambient air temperature [K]
k = 177; % thermal conductivity [W/m-K]
h = 650; % heat transfer coefficient [W/m^2-K]
q = 250; % theraml radiation flux W/m^2
N = 10000; % iteration

syms x1

for n=1:100
f(n)=int((2*h*L/(n*pi()*k)*sin(n*pi()*x1/(2*L))+cos(n*pi()*x1/(2*L))),x1,0,W)
T(n)=Tamb+(Tb-Tamb)*sum(f(n))
end

Error:

Code is taking a long time. Have to stop it.

Mando Knight
2011-12-06, 12:59 AM
Not sure what it's complaining about now, but the way the code's written up you don't need the sum() in there anymore.

Deathslayer7
2011-12-06, 01:09 AM
L = 0.075; % length [m]
W = 0.015; % width [m]
d = 0.003; % nodal spacing [m]
Tb = 393; % base temperature [K]
Tamb = 293; % ambient air temperature [K]
k = 177; % thermal conductivity [W/m-K]
h = 650; % heat transfer coefficient [W/m^2-K]
q = 250; % theraml radiation flux W/m^2
N = 10000; % iteration

syms x1

for n=1:100
f(n)=int((2*h*L/(n*pi()*k)*sin(n*pi()*x1/(2*L))+cos(n*pi()*x1/(2*L))),x1,0,W);
T(n)=Tamb+(Tb-Tamb)*f(n);
end

T(1)
T(2)

Get this: ??????

ans =
293 - (15*(6317296170330047*2^(1/2)*(5^(1/2) + 5)^(1/2) - 36028797018963968*5^(1/2) + 10759612337643780))/(144115188075855872*pi)
ans =
(15*(72057594037927936*2^(1/2)*(5 - 5^(1/2))^(1/2) - 6317296170330047*5^(1/2) + 18951888510990141))/(576460752303423488*pi) + 293
>>

Deathslayer7
2011-12-06, 01:13 AM
Going to take a break for now, but if anyone has some helpful input it is much appreciated. And thank you Mando Knight for the help.

I'll get back to this later tonight. Going to go grab some dinner.

Generic Archer
2011-12-07, 07:04 AM
Can you give me the actual function?
The way that you've set it out is not the way I would do it... I can't follow the use of int, and I think you might be using a different version of matLAB to me, as pi() just returns 'pi' for me.

I generally use Mathematica for integrals, but my memory of doing it in matLAB is a straight forward sum.

The total integral will be sum(T) as a final line, assuming the rest of it works properly(unless of course that gets incorporated into the int part...)... interestingly this seems to create some strange undocumented functions/numbers and is also a ridiculously large number.

Mando Knight
2011-12-07, 12:33 PM
Get this: ??????

ans =
293 - (15*(6317296170330047*2^(1/2)*(5^(1/2) + 5)^(1/2) - 36028797018963968*5^(1/2) + 10759612337643780))/(144115188075855872*pi)
ans =
(15*(72057594037927936*2^(1/2)*(5 - 5^(1/2))^(1/2) - 6317296170330047*5^(1/2) + 18951888510990141))/(576460752303423488*pi) + 293
>>
...Looks like the sort of thing my calculator does when it's in Exact mode. Never seen that happen with MatLAB.

Deathslayer7
2011-12-07, 05:33 PM
exact function? Sure here it is. Not for the weak of heart.

spoilered for stretchyness. Look at Part C as that is what I need help with.

http://i198.photobucket.com/albums/aa125/death_slayer7/Scan001_Page_2.png

Mando Knight
2011-12-07, 06:02 PM
That is, without a doubt, the ugliest "analytical" solution I have ever seen (analytical solution with a summation? That doesn't even make sense, let alone confusing a variable of integration with a function variable...).

Anyway, your previous output dump looks like it was on the right track at least...

...try telling it to output the value in double format? Stuff = double(F(Whatever))

Deathslayer7
2011-12-07, 06:29 PM
And now you know why I only wrote out part of it. :smallbiggrin::smalltongue:

I got class now but in about four hours from now, I'll be back to working on it.