L=1;
alpha= 10^-3;
T1=800;
T2=200;
x=0:0.01:L;
N=50;
t=0:5:25;
A_0=(T1+T2)/2;
Teaxct=zeros(length(x),length(t));
for m=1:length(x)
for k=1:5:length(t)
for n=1:(N)
A_n(n)=(2*(T1-T2)/pi*(n))*(sin((pi/2)*(n)))*(cos((pi*n*m)/L))*(exp(-1*alpha*((pi*(n))/L)^2*k));
Texact(m,k)=A_0+A_n(n)
end
end
end

2 件のコメント

KSSV
KSSV 2020 年 8 月 25 日
Why three loops? Type error here in the variable Teaxct.
You can achieve what you want with meshgrid.
Muhammad Umar Khan
Muhammad Umar Khan 2020 年 8 月 25 日
One for each variable

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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 8 月 26 日

0 投票

In your third loop, the values of m and k do not change. This means the results of each loop are written to the same element of Texact, overwriting the previous value. The result is you only capture the final value in your third loop.
Your code also runs really slow because you are printing out the results of every single interation.
You also have a typo I suspect. You initialize Teaxct but then use Texact in your loops.

2 件のコメント

Muhammad Umar Khan
Muhammad Umar Khan 2020 年 8 月 26 日
How to resolve it any idea
Cris LaPierre
Cris LaPierre 2020 年 8 月 26 日
Fix your typo, add a semicolon to the end of your Texact line, and then describe what your expected output size is. If you want to capture every value, you need to add a third dimension to Texact
Texact(m,k,n)= ...

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2020 年 8 月 25 日

コメント済み:

2020 年 8 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by