Analytical solution for 1D heat equation
Show older comments
Hello,
I need help with analytical solution for following heat equation.

I already have numerical solution using euler(explicit and implicit).
Adding code for explicit solution...
clear all;
close all;
clc
%% zadani uhloy
%def oblasti
a=0; %x nalezi {a,b}
b=2*pi;
d=1; %okrajova podminka t nalezi {0,d}
h=2*pi/100; %volba kroku x
p=100; %koeficient pred druhou parcialni derivaci U dle x
tau=(h^2*1/2)/p % výpočet časového kroku
%% priprava na vypocet
%vypocet mnozstvi kroku
stx=round(1+(2*pi-a)/h);
stt=1+d/tau;
x(1)=a;
t(1)=0;
%vypocet sigma
sig=p*tau/h^2
%% sestavovani site
%parametrizace delky x
for j=2:stx
x(j)=a+(j-1)*h;
end
%parametrizace casu t
for k=2:stt
t(k)=(k-1)*tau;
end
%preddefinovani matice vyslednych U
%U=zeros(stx,stt);
%funkce f
%for j=1:stx
% for k=1:stt
% f(j,k)=exp(-t(k));
% end
%end
% pocatecni podminky
for j=1:stx
U(j,1)=sin(x(j))+(1/10)*sin(10*x(j));
end
% okrajove podminky
for k=1:stt
U(1,k)=0;
U(stx,k)=0;
end
%% vypocet
%vypocet jednotlivych hodnot U uvnitr mnoziny
%tj bez OP a PP ktere byly jizvypocteny
for k=2:stt
for j=2:(stx-1)
U(j,k)=sig*(U(j+1,k-1)+U(j-1,k-1))+(1-2*sig)*U(j,k-1);%+tau*f(j,k-1);
end
end
figure(1)
sur=surf(t, x, U);
set(sur,'LineStyle','none')
figure(2)
plot(x, U(:,1))
%U1_p1=U;, t1_p1=t;
%U1_p10=U; t1_p10=t;
U1_p100=U; t1_p100=t;
%save U1_p1 , save t1_p1
%save U1_p10, save t1_p10
save U1_p100, save t1_p100
I need the same solution as my Figure 1 for different inputs of the constant 'a' in my code it is p, because I need to compare it with explicit and implicit solution.
FIgure (1) a=100

FIgure (1) a=1

I don't know how to do analytical solution in MATLAB for it.
Could someone help me please?
Thank you very much for your time and help! It will really help me.
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!