please help i keep getting erro

2 views (last 30 days)
Samson
Samson on 8 Mar 2023
Commented: Samson on 13 Mar 2023
function sol=samsonwork
global Br Sc delta P K R n epsilon
%x=linspace(-1,1,11);
r=0:0.01:3;
Br=1;Sc=0.4;n=3;delta=0;R=0.5;epsilon=0.1;P=0.3;K=0.3;
solinit=bvpinit(r,[0,0,0,0,0,0]);
sol=bvp4c(@samsonfun,@samsonbc,solinit);
% plot(ans.x(1,:),ans.y(1,:))
end
function f=samsonfun(~,y)
% -Df*y(8)
global Br Sc delta P K R n epsilon g
g = y(3)/ (1+epsilon*y(3));
f=[y(2)
-P
y(4)
R*y(4)-Br*(y(2))^2+delta*(1+epsilon*y(3))* exp g
y(6)
Sc*K*(1+epsilon*y(3))^n *exp g];
end
function res=samsonbc(ya,yb)
%global s lambda alpha
res=[ya(1)
yb(1)-1
ya(3)
yb(3)
ya(5)-1
yb(5)];
end
  3 Comments
Torsten
Torsten on 10 Mar 2023
@Samson comment moved here.
That's my second order equations
Torsten
Torsten on 10 Mar 2023
Edited: Torsten on 10 Mar 2023
What I mean is:
"exp g" is not a valid MATLAB expression - it will throw an error.
So which mathematical object should "exp g " represent ?
Do you mean exp(g) ? In this case, your code works (see below).

Sign in to comment.

Accepted Answer

Torsten
Torsten on 10 Mar 2023
samsonwork()
ans = struct with fields:
solver: 'bvp4c' x: [0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300 0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000 0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700 0.2800 0.2900 0.3000 0.3100 0.3200 0.3300 … ] y: [6×301 double] yp: [6×301 double] stats: [1×1 struct]
function sol=samsonwork
global Br Sc delta P K R n epsilon
%x=linspace(-1,1,11);
r=0:0.01:3;
Br=1;Sc=0.4;n=3;delta=0;R=0.5;epsilon=0.1;P=0.3;K=0.3;
solinit=bvpinit(r,[0,0,0,0,0,0]);
sol=bvp4c(@samsonfun,@samsonbc,solinit);
plot(sol.x,[sol.y(1,:);sol.y(2,:)])
% plot(ans.x(1,:),ans.y(1,:))
end
function f=samsonfun(~,y)
% -Df*y(8)
global Br Sc delta P K R n epsilon g
g = y(3)/ (1+epsilon*y(3));
f=[y(2)
-P
y(4)
R*y(4)-Br*(y(2))^2+delta*(1+epsilon*y(3))* exp(g)
y(6)
Sc*K*(1+epsilon*y(3))^n *exp(g)];
end
function res=samsonbc(ya,yb)
%global s lambda alpha
res=[ya(1)
yb(1)-1
ya(3)
yb(3)
ya(5)-1
yb(5)];
end

More Answers (0)

Categories

Find more on Linear Model Identification 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!