Any mathematical mistake in my script ?
1 view (last 30 days)
Show older comments
Chee Hao Hor
on 10 Aug 2021
Commented: Chee Hao Hor
on 12 Aug 2021
Hi, I am trying to plot the self-derived analytical solution using matlab. However, I get different answer from what I obtained using excel sheet.
I suspect the mistake is in somewhere within this script, where I could have miss out.
Could anyone spare a help here ?
Self-derived Analytical Solution :
syms n y real
assume([n y] >= 0);
Y = 0:0.02:1;
b =1; t=1; br=1; Pr=1;
%t = t*
K1=(1-exp(-((2.*n)+1).^2.*pi.^2.*t./(4.*Pr)))./(((2.*n)+1).^2.*pi.^2);
K2=((((2.*n)+1).^2.*pi.^2.*exp(-((2.*n)+1).^2.*pi.^2.*t./(4.*Pr)))-(((2.*n)+1).^2.*pi.^2.*cos(2.*b.*t))-(8.*b.*Pr.*sin(2.*b.*t)))./((64.*b.^2.*Pr.^2)+(((2.*n)+1).^4.*pi.^4));
T = subs( sum( subs( 8.*br./(((2.*n)+1).*pi).*(K1+K2).*sin((((2.*n)+1)./2).*pi.*y), n, 1:100 )), y, Y );
Tn = double(T);
disp(Tn);
plot(Tn,Y);
Thanks,
Andy
0 Comments
Accepted Answer
Alan Stevens
on 10 Aug 2021
Easier to check like this
b=1; t=1; br=1; Pr=1;
d = @(n) (2*n + 1)*pi;
c = @(n) d(n).^2;
k1 = @(n) ( 1 - exp( -c(n)*t/(4*Pr) ) )./c(n);
k2 = @(n) c(n).*exp( -c(n)*t/(4*Pr) ) - c(n)*cos(2*n*t) - 8*b*Pr*sin(2*b*t);
k3 = @(n) c(n).^2 + 64*b^2*Pr^2;
K = @(n) k1(n) + k2(n)./k3(n);
term = @(y,n) 8*br./d(n).*K(n).*sin(d(n)*y/2);
y = 0:0.02:1;
N = numel(y);
T = zeros(1,N);
for i=1:N
for n = 0:100
T(i) = term(y(i),n) + T(i);
end
end
figure
plot(y,T),grid
xlabel('y'), ylabel('T')
3 Comments
Alan Stevens
on 11 Aug 2021
"1. Shouldn't it be all using .* and ./ since we are summing up the "n" term by term (consider as element wise sum up right) ? I tried using your current script, it gives same results with I added all with .* and ./. I could not imagine how they sum up using mixed of *; .*; / and ./."
Yes, you can replace the .* etc by just . I put .* initially, as I hadn't decided if I would use a loop or vector indexing.
"2. In your case, you first sum up the T for a particular of y location (here is up to 100 n terms, increment 1 each time). Then do the same for rest of the discretized y which defined by array of zeros N elements (from 0 to 1, increment 0.02 each time), am i right ?"
Yes, that's right.
"3. If i have a similar analytical solution that consists of triple summation terms, it involved piecewise function, using for loop method should work also right ?"
Yes, it should.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!