write y''(x)=1/sqrt(x)*y(x)^(3/2) in standard form in matlab

To write the second-order differential equation y''(x) = 1/sqrt(x) * y(x)^(3/2) in the standard form suitable for Matlab's ODE solvers, we need to convert it into a system of first-order differential equations:

main.m
y'(x) = z(x)
z'(x) = 1/sqrt(x) * y(x)^(3/2)
44 chars
3 lines

Here, y and z are new functions defined as the first and second derivatives of the original function y, respectively. Note that the initial condition for this system should include y(1), since the given equation is not defined for x=0.

We can then use Matlab's ode45 solver to numerically integrate the system of differential equations:

main.m
% define the system of differential equations
dydx = @(x, y) [y(2); 1/sqrt(x)*y(1)^(3/2)];
% set the initial condition
y0 = [1; 0];
% solve the system from x=1 to x=2
[x, y] = ode45(dydx, [1, 2], y0);
% plot the solution
plot(x, y(:, 1))
xlabel('x')
ylabel('y(x)')
265 chars
11 lines

This code defines an anonymous function dydx that takes x and y=[y(x); z(x)] as inputs and returns the corresponding derivatives [y'(x); z'(x)]. It then sets the initial condition y0 as [y(1); y'(1)] = [1; 0] and solves the system of differential equations numerically using ode45. Finally, it plots the solution y(x) as a function of x.

gistlibby LogSnag