Question

answer in matlab code

Employ the bvp4c command to find the approximate solution of the boundary value problem governed by the second-order nonhomog
0 0
Add a comment Improve this question Transcribed image text
Answer #1


nt we. have 2- 2 HeMce 2Matlab code for solving ode using bvp4c clear all close all %solution using bvp4c solinit - bvpinit(linspace (0,1),1 0]) sol-Y(x) vs. x plot Using bvp4c dsolve 0 4.5 3.5 2.5 0.1 0 03 0.5 06 0700.91 Published with MATLAB R2018a

%Matlab code for solving ode using bvp4c
clear all
close all

%solution using bvp4c

solinit = bvpinit(linspace(0,1),[1 0]);
sol= bvp4c(@twoode,@twobc,solinit);

xx=linspace(0,1);
yy=deval(sol,xx);
plot(xx,yy(1,:),'linewidth',2)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%solution using dsolve
syms y(x)
eqn = diff(y,x,2)+2*diff(y,x,1)+y(x) == x^2;
cond = [y(0)==5, y(1)==2];
ySol(x) = dsolve(eqn,cond);
fprintf('Solution using dsolve is y(x)=')
disp(ySol(x))

for i=1:length(xx)
    y_ext(i)=ySol(xx(i));
end

hold on
plot(xx,y_ext,'o','linewidth',2)
title('Y(x) vs. x plot')
xlabel('x')
ylabel('y(x)')
legend('Using bvp4c','using dsolve')


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function dydx = twoode(x,y)

    dydx= [y(2); (x.^2-2*y(2)-y(1))];
  
end

function res =twobc(ya,yb)
    res = [ya(1)-5; yb(1)-2];
end


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
answer in matlab code Employ the bvp4c command to find the approximate solution of the boundary value problem governed by the second-order nonhomogeneous differential equation, 9. with the bound...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT