I write a matlab code for the problem, and i want to compare the numerucal and the exact solution at t=0.5 but the graph of the soultions are very different.
The problem is in the following:
% Parameters
L = 5; % Length of the rod
T = 1; % Total time
Nx = 100; % Number of spatial points
Nt = 500; % Number of time steps
alpha = 0.01; % Thermal diffusivity
% Discretization
dx = 0.1; % Spatial step size
dt = 0.04; % Time step size
r = alpha * dt / dx^2; % Stability parameter for the scheme
% Initial condition
x = linspace(0, L, Nx);% generates Nx points. The spacing between the points is (L-0)/(Nx-1).
u = cos(x-0.5); % initial condition
% Preallocate solution matrix
U = zeros(Nx, Nt+1); % returns an Nx-by-Nt matrix of zeros
U(:,1) = u; %extracts all the elements from the first column of matrix
% Time-stepping loop
for n = 1:Nt
% Update the solution using explicit scheme for the Heat Equation
You accepted the answer to this question. Then you asked it just again, 42 minutes ago. I closed the duplicate question, since it asks nothing you should not have learned here.
somtimes I change the interval up to 5 to see the bahavior of the graph. however , how we compare the exact solution with the numerical at specific time since they are differents.
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
Translated by
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.