What is wrong in code of diffusion equation problem?

9 ビュー (過去 30 日間)
Attila Monteiro de Abreu
Attila Monteiro de Abreu 2016 年 9 月 17 日
回答済み: Byron Castillo 2021 年 1 月 22 日
a=4; b=4; na=20; nb=16; k=5; to=80;
clear T
x=linspace(0,a,na);
y=linspace(0,b,nb);
[X,Y]=meshgrid(x,y);
for i=1:nb
for j=1:na
T(i,j)=0;
For n=1:k
Ns=2*n-1;
T(i,j)=T(i,j)+sin(ns*pi*X(i,j)/a).*sinh(ns*pi*Y(i,j)/a)/(sinh(ns*pi*b/a)*ns);
End
T(i,j)=T(i,j)*4*To/pi;
End
End
Mesh(X,Y,T)
Xlabel(x (m));ylabel(y (m));zlabel(T(^oC))

採用された回答

Walter Roberson
Walter Roberson 2016 年 9 月 18 日
First of all you need to use for and end not For and End -- MATLAB is case sensitive.
Secondly, your line
Xlabel(x (m));ylabel(y (m));zlabel(T(^oC))
uses Unicode Character 'LEFT SINGLE QUOTATION MARK' (U+2018) and Unicode Character 'RIGHT SINGLE QUOTATION MARK' (U+2019) instead of apostrophe. U+2018 and U+2019 are also known as "smart quotes" because some editors automatically change apostrophes around words to these quotes because those quotes are used in publishing and writing text (but seldom in computer code.)
  1 件のコメント
Attila Monteiro de Abreu
Attila Monteiro de Abreu 2016 年 9 月 18 日
編集済み: Attila Monteiro de Abreu 2016 年 9 月 18 日
Thank you so much brother!!! You help me in my work of conclusion of course in Engenering Mechanical! I'm really greatfull!!

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

その他の回答 (1 件)

Byron Castillo
Byron Castillo 2021 年 1 月 22 日
a=5; b=4; na=20; nb=16; k=5; T0=80;
clear T
x=linspace(0,a,na);
y=linspace(0,b,nb);
[X,Y]=meshgrid(x,y);
for i=1:nb
for j=1:na
T(i,j)=0;
for n=1:k
ns=2*n-1;
T(i,j)=T(i,j)+sin(ns*pi*X(i,j)/a).*sinh(ns*pi*Y(i,j)/
a)/(sinh(ns*pi*b/a)*ns);
end
T(i,j) = T(i,j)*4*T0/pi;
end
end
mesh(X,Y,T)
xlabel('x (m)'); ylabel('y (m)'); zlabel('T ( ^oC)')

カテゴリ

Help Center および File ExchangePhysics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by