Category:Installation
Jump to navigation
Jump to search
% Define the function dy/dx = yx - x^3 f = @(x, y) y*x - x^3;
% Initial conditions x0 = 0; y0 = 1; h = 0.6; xf = 1.8;
% Number of steps n = round((xf - x0) / h);
% Initialize arrays for solutions x_values = x0:h:xf;
% Euler's Explicit Method y_euler = zeros(1, n+1); y_euler(1) = y0; for i = 1:n
y_euler(i+1) = y_euler(i) + h * f(x_values(i), y_euler(i));
end
% Display results
disp('x values:'), disp(x_values);
disp('Euler method results:'), disp(y_euler);
% Plot the solutions
figure;
plot(x_values, y_euler, '-o', 'DisplayName', 'Euler Method');
hold on;
xlabel('x');
ylabel('y');
title('Solutions to dy/dx = yx - x^3');
legend;
grid on;
Pages in category "Installation"
The following 10 pages are in this category, out of 10 total.