Using Shooting Method on Euler Method to Solve Second Order BVP
Show older comments
% Project 3 Shooting Method Using Euler Method
%y''+(1-x)y'+xy=x, y(0) =0, y(1) =2
clear; clc
%parameters
x0 = 0;
y0 = 0;
xf = 1;
u0 = 1;%input('yp value at intial x value:\n');
y1 = 2; %input('Input second y condition value:\n');
n = 10;
x(1) = x0;
y(1) = y0;
u(1) = u0;
h = (xf-x0)/n;
t = x0:h:xf ;
for i = 2:length(t)
x(i) = x(i-1)+h;
y(i) = y(i-1)+u(i-1)*h;
u(i) = u(i-1)+h*(x(i-1)-(x(i-1)*y(i-1))-(1-x(i-1)*u(i-1)));
end
A1 = [x;y];
fprintf('\n%8.4f %8.4f\n', A1)
plot(x,y,'r')
This code numerically solves the second ODE using shooting method on Euler Method. However, I'm trying to figure out how to get matlab to automatically test y' values at x0 (I have this variable as u0 in my code) in the iterations until it finds a y' value that satisfies the second boundry condition at y(1). I tried using linspace for u0 to test a string of numbers but it isn't working.
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!