Write a MATLAB program to solve the following two-point boundary
value problem for
d^2theta/dt^2 = -theta(t); 0 < t < 2theta; theta(0) = 0.7; theta(2pie) = 0.7:
% y = [theta; d_theta/d_t]
bvpfcn = @(t, y) [y(2); -y(1)]; % right side function
bcfcn = @(ya, yb) [ya(1)-0.7; yb(1)-0.7]; % boundary conditions
guess = @(t) [1; 0]; % initial guess
xmesh = linspace(0, 2*pi, 10);
solinit = bvpinit(xmesh, guess);
sol = bvp4c(bvpfcn, bcfcn, solinit);
plot(sol.x, sol.y, '-o')
legend(["theta", "theta'"], "location", "southeast")
Comments
Leave a comment