heat equation not working

This is a solution for my homework, but the code gives us an error on the next line
I appreciate your help in that that
T(i,j+1)=T(i.j)+((dt)/(dx.^2))*(T(i+1,j)-2*T(i,j)+T(i-1,j));
clc;
clear all;
for i=1:15
x(i)=i;
x1(i)=(i-1)/15;
for j=1:10
T(i,j)=0;
end
end
T(x,1)=sin(pi*x1);
dx=0.1;
dt=0.04;
for j=1:10
for i=2:15
T(i,j+1)=T(i.j)+((dt)/(dx.^2))*(T(i+1,j)-2*T(i,j)+T(i-1,j));
end
end
for i=1:15
T0(i)=T(i,1);
T1(i)=T(i,2);
T2(i)=T(i,3);
T3(i)=T(i,4);
T4(i)=T(i,5);
T5(i)=T(i,6);
end
title("Heat");
ylabel("y");
xlabel("x");
legend("HEAT EQ");

Réponses (1)

Voss
Voss le 12 Déc 2021

0 votes

The error is because you have a typo in that line:
T(i.j)
should be:
T(i,j)
Once you correct that, you will get a new error on the same line. This error is due to trying to refer to T(i+1,j) when i is 15, i.e., T(16,j) but T has size 15 in dimension 1. To fix that, I guess the i loop should go from 2 to 14 rather than 2 to 15:
for i=2:14

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by