Please help me to run this simple code. I want to check the definition the third oder of ODE is true of false in projfun function.
where c,alfa,mu,beta are constant.
% code
function sol= proj
clc;clf;clear;
myLegend1 = {};myLegend2 = {};
rr = [0.8]
for i =1:numel(rr)
c= rr(i);
alfa=6;
b=6;nu=4;
y0 = [1,1,1];
options =bvpset(‘stats’,’on’,’RelTol’,1e-4);
m = linspace(-3,3);
solinit = bvpinit(m,y0);
sol= bvp4c(@projfun,@projbc,solinit,options);
figure(1)
% plot(sol.x,(sol.y(1,:)))
yExact=nu*(3/b)*(sech((sqrt(nu)*0.5)*sol.x)).^2;
plot(sol.x,(sol.y(1,:)),’r’,sol.x,yExact,’b’)
grid on,hold on
myLegend1{i}=[‘b1= ‘,num2str(rr(i))];
% figure(2)
% % plot(sol.x,(sol.y(1,:)))
% grid on,hold on
% myLegend2{i}=[‘b1= ‘,num2str(rr(i))];
i=i+1;
end
figure(1)
legend(myLegend1)
hold on
figure(2)
legend(myLegend2)
function dy= projfun(~,y)
dy= zeros(3,1);
E = y(1);
dE = y(2);
ddE=y(3);
dy(1) = dE;
dy(2) =ddE;
dy(3)=(1/b)*(nu*ddE+dE*(c-alfa*E));
end
end
function res= projbc(ya,yb)
res= [ya(1);
ya(2);
yb(1);
];
endwhere c,alfa,mu,beta are constant.
% code
function sol= proj
clc;clf;clear;
myLegend1 = {};myLegend2 = {};
rr = [0.8]
for i =1:numel(rr)
c= rr(i);
alfa=6;
b=6;nu=4;
y0 = [1,1,1];
options =bvpset(‘stats’,’on’,’RelTol’,1e-4);
m = linspace(-3,3);
solinit = bvpinit(m,y0);
sol= bvp4c(@projfun,@projbc,solinit,options);
figure(1)
% plot(sol.x,(sol.y(1,:)))
yExact=nu*(3/b)*(sech((sqrt(nu)*0.5)*sol.x)).^2;
plot(sol.x,(sol.y(1,:)),’r’,sol.x,yExact,’b’)
grid on,hold on
myLegend1{i}=[‘b1= ‘,num2str(rr(i))];
% figure(2)
% % plot(sol.x,(sol.y(1,:)))
% grid on,hold on
% myLegend2{i}=[‘b1= ‘,num2str(rr(i))];
i=i+1;
end
figure(1)
legend(myLegend1)
hold on
figure(2)
legend(myLegend2)
function dy= projfun(~,y)
dy= zeros(3,1);
E = y(1);
dE = y(2);
ddE=y(3);
dy(1) = dE;
dy(2) =ddE;
dy(3)=(1/b)*(nu*ddE+dE*(c-alfa*E));
end
end
function res= projbc(ya,yb)
res= [ya(1);
ya(2);
yb(1);
];
end where c,alfa,mu,beta are constant.
% code
function sol= proj
clc;clf;clear;
myLegend1 = {};myLegend2 = {};
rr = [0.8]
for i =1:numel(rr)
c= rr(i);
alfa=6;
b=6;nu=4;
y0 = [1,1,1];
options =bvpset(‘stats’,’on’,’RelTol’,1e-4);
m = linspace(-3,3);
solinit = bvpinit(m,y0);
sol= bvp4c(@projfun,@projbc,solinit,options);
figure(1)
% plot(sol.x,(sol.y(1,:)))
yExact=nu*(3/b)*(sech((sqrt(nu)*0.5)*sol.x)).^2;
plot(sol.x,(sol.y(1,:)),’r’,sol.x,yExact,’b’)
grid on,hold on
myLegend1{i}=[‘b1= ‘,num2str(rr(i))];
% figure(2)
% % plot(sol.x,(sol.y(1,:)))
% grid on,hold on
% myLegend2{i}=[‘b1= ‘,num2str(rr(i))];
i=i+1;
end
figure(1)
legend(myLegend1)
hold on
figure(2)
legend(myLegend2)
function dy= projfun(~,y)
dy= zeros(3,1);
E = y(1);
dE = y(2);
ddE=y(3);
dy(1) = dE;
dy(2) =ddE;
dy(3)=(1/b)*(nu*ddE+dE*(c-alfa*E));
end
end
function res= projbc(ya,yb)
res= [ya(1);
ya(2);
yb(1);
];
end bvp4c, ode MATLAB Answers — New Questions