MATLAB Answers

Any mathematical mistake in my script ?

1 ビュー (過去 30 日間)
Chee Hao Hor
Chee Hao Hor 2021 年 8 月 10 日
コメント済み: Chee Hao Hor 2021 年 8 月 12 日
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

採用された回答

Alan Stevens
Alan Stevens 2021 年 8 月 10 日
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 件のコメント
Chee Hao Hor
Chee Hao Hor 2021 年 8 月 12 日
Alright, for loop method, it is substituting the equation every sum set of n, giving numerical value for each discretized y. That's why no need used element wise.
Whereas my original script only substitute the sum up y at the last step, so need element wise.
Thanks @Alan Stevens !

サインインしてコメントする。

その他の回答 (0 件)

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by