Error in untitled22>solveHeatEquation1D (line 32) U(N+2,n+1) = beta(t); Error in untitled22 (line 11) [t, x, U] = solveHeatEquation1D(T, a, b,mu, u0,alpha, N, M);
a = 0; b = 1;
T = 2;
mu = 0.5;
alpha =1;
gamma=@(t) 0 ;
beta=@(t) 0 ;
u0 = @(x) (x.^4-x.^2);
N = 100;
M = 100;
[t, x, U] = solveHeatEquation1D(T, a, b,mu, u0,alpha, N, M);
surf(t, x, U);
shading interp , colormap ( ‘jet’ )
xlabel(‘t’);
ylabel(‘x’);
zlabel(‘U’);
title(‘la Solution de equation par methode de diff finis’);
function [t, x, U] = solveHeatEquation1D(T, a, b, mu, u0,alpha, N, M)
dt = T/M;
t = 0:dt:T;
dx = (b-a)/N+1;
x = a:dx:b;
U = zeros(N+2, M+1);
E = mu *dt/dx^2;
C = 1 – 2*E;
D = alpha *(dt/(2*dx));
U(:,1) = u0(x);
for n = 1:M
for i = 2:N+1
U(N+2,n+1) = beta(t);
U(1,n+1) = gamma(t);
U(i,n+1) = (E-D)*U(i+1,n) + C*U(i,n) + (D-E)*U(i-1,n);
end
end
enda = 0; b = 1;
T = 2;
mu = 0.5;
alpha =1;
gamma=@(t) 0 ;
beta=@(t) 0 ;
u0 = @(x) (x.^4-x.^2);
N = 100;
M = 100;
[t, x, U] = solveHeatEquation1D(T, a, b,mu, u0,alpha, N, M);
surf(t, x, U);
shading interp , colormap ( ‘jet’ )
xlabel(‘t’);
ylabel(‘x’);
zlabel(‘U’);
title(‘la Solution de equation par methode de diff finis’);
function [t, x, U] = solveHeatEquation1D(T, a, b, mu, u0,alpha, N, M)
dt = T/M;
t = 0:dt:T;
dx = (b-a)/N+1;
x = a:dx:b;
U = zeros(N+2, M+1);
E = mu *dt/dx^2;
C = 1 – 2*E;
D = alpha *(dt/(2*dx));
U(:,1) = u0(x);
for n = 1:M
for i = 2:N+1
U(N+2,n+1) = beta(t);
U(1,n+1) = gamma(t);
U(i,n+1) = (E-D)*U(i+1,n) + C*U(i,n) + (D-E)*U(i-1,n);
end
end
end a = 0; b = 1;
T = 2;
mu = 0.5;
alpha =1;
gamma=@(t) 0 ;
beta=@(t) 0 ;
u0 = @(x) (x.^4-x.^2);
N = 100;
M = 100;
[t, x, U] = solveHeatEquation1D(T, a, b,mu, u0,alpha, N, M);
surf(t, x, U);
shading interp , colormap ( ‘jet’ )
xlabel(‘t’);
ylabel(‘x’);
zlabel(‘U’);
title(‘la Solution de equation par methode de diff finis’);
function [t, x, U] = solveHeatEquation1D(T, a, b, mu, u0,alpha, N, M)
dt = T/M;
t = 0:dt:T;
dx = (b-a)/N+1;
x = a:dx:b;
U = zeros(N+2, M+1);
E = mu *dt/dx^2;
C = 1 – 2*E;
D = alpha *(dt/(2*dx));
U(:,1) = u0(x);
for n = 1:M
for i = 2:N+1
U(N+2,n+1) = beta(t);
U(1,n+1) = gamma(t);
U(i,n+1) = (E-D)*U(i+1,n) + C*U(i,n) + (D-E)*U(i-1,n);
end
end
end error in untitled22 solveheatequation1d (line 32) MATLAB Answers — New Questions