Example uploaded here: http://www.2shared.com/document/QV9t-ifp/BVP-shooting-exa
ID: 1858427 • Letter: E
Question
Example uploaded here: http://www.2shared.com/document/QV9t-ifp/BVP-shooting-example.html
Solve the Boundary Value Problem:
y’’ + 2y’ – x2y = x; y(0) = 1, y(1) = 1.75
Use the Shooting method. Obtain the solutions by solving a system of two first order ODE which is equivalent to the second order ODE.
Use Modified Euler, with h = 0.2
Use two guesses for y'(1), namely: y'(1)=1.5 and y'(1)=2.5
So I asked a question before and rewrote the equation as a system of 1st order ODE:
y"+2y'-x^2y=x
or
y'' = x - 2y' + x^2y
x1 = y , x2 = y'
x1' = y' = x2'
x2' = y'' = x - 2y' + x^2y
= x - 2x2 + x^2*x1
x2' = x - 2x2 + x^2*x1
But now I do not know how to input the information into my matlab script. Can anyone help me with this and post the correct code I need?
(Note the matlab script is from last year and solved a different equation y"-(1-(x/5))y=x which needs to be updated to this new equation y’’ + 2y’ – x2y = x)
function yeulerpc=eulerpc (x, y1)
%
% independent variable x
% unknowns y,z
% equations:
% yprime = z y(1) = 2
% zprime = (1 - x/5) y + x ; z(1) = -1.5
clear
clc
x = 1 : 0.1 : 3 ;
%
y(1) = 2;
z(1) = -3.49437;
%
fprintf(' ')
fprintf(' Euler Predictor-Corrector i x y z ')
%
fprintf(' - %9.5f %9.5f %9.5f ',1 ,x(1),y(1),z(1));
%
yp(1) = z(1) ;
zp(1) = (1.0 - x(1)/5.0)*y(1) + x(1);
for i=2:length(x)
%
dx = x(i) - x(i-1) ;
% Predictor step:
y(i) = y(i-1) + dx*yp(i-1);
z(i) = z(i-1) + dx*zp(i-1);
yp(i) = z(i) ;
zp(i) = (1.0 - x(i)/5.0)*y(i) + x(i);
%
% Corrector step:
y(i) = y(i-1) + 0.5*(yp(i-1)+yp(i))*dx ;
z(i) = z(i-1) + 0.5*(zp(i-1)+zp(i))*dx ;
yp(i) = z(i) ;
zp(i) = (1.0 - x(i)/5.0)*y(i) + x(i);
%
fprintf(' - %9.5f %9.5f %9.5f ',i,x(i),y(i),z(i));
%
end
plot(x,y,'linewidth',2.0),grid,title('prjct 7 - Euler-PC')
Explanation / Answer
U have solved it correctly ....
function yeulerpc=eulerpc (x, y1)
%
% independent variable x
% unknowns y,z
% equations:
%yprime = z    y(1) = 2
%zprime = (1 - x/5) y + x ;   z(1) = -1.5
clear
clc
x = 1 : 0.1 : 3 ;
y(1)Â = 2;
z(1) = -3.49437;
fprintf(' ')
fprintf('  Euler Predictor-Corrector  i        x          y           z ')
fprintf(' -  %9.5f  %9.5f    %9.5f ',1 ,x(1),y(1),z(1));
yp(1)Â = z(1) ;
zp(1) = (1.0 - x(1)/5.0)*y(1) + x(1);
for i=2:length(x)
dx = x(i) - x(i-1) ;
% Predictor step:
for i=2:length(x)
{
y(i) = y(i-1) + dx*yp(i-1);
z(i) = z(i-1) + dx*zp(i-1);
yp(i)Â = z(i) ;
zp(i) = (1.0 - x(i)/5.0)*y(i) + x(i);
}
Corrector step:
for i=2:length(x)
{
y(i) = y(i-1) + 0.5*(yp(i-1)+yp(i))*dx ;
z(i) = z(i-1) + 0.5*(zp(i-1)+zp(i))*dx ;
yp(i)Â = z(i) ;
zp(i) = (1.0 - x(i)/5.0)*y(i) + x(i);
fprintf(' -  %9.5f  %9.5f    %9.5f ',i,x(i),y(i),z(i));
}
%
end
plot(x,y,'linewidth',2.0),grid,title('prjct 7 - Euler-PC')
% I hope it should work
%%%%plsz rate me 1st %%
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.