Back to Browse

ODE45 MATLAB2025

62 views
Jan 2, 2026
2:12

For the classes of Atul Roy script % ode45 is a built-in MATLAB function to find numerical solutions to differential equations. % It gives more accurate results than Euler's method by adjusting step sizes automatically. % Define the ODE as a function: dy/dx = sin(xy/2) + (2x/sqrt(y^2+1) f = @(x, y) sin(x*y/2) + 2*x/sqrt(y^2+1); % Solve the ODE from x = 0 to x = 2 with initial condition y(0) = 1 [x_vals, y_vals] = ode45(f, [0 2], 1); % Plot the solution plot(x_vals, y_vals), xlabel('x'), ylabel('y(x)') title('Solution of dy/dx = sin(xy/2) + (2x/sqrt(y^2+1)') % Approximate y at x = 1, with interp1 to interpolate y_at_1 = interp1(x_vals, y_vals, 1); fprintf('Approximate value of y at x = 1: %.6f\n', y_at_1) %\n is newline character — it tells MATLAB to go to the next line after printing. %So '%.6f\n' means: print the number with 6 decimal places, then move to a new line.

Download

1 formats

Video Formats

360pmp41.5 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

ODE45 MATLAB2025 | NatokHD