Why is my index becoming zero when using a driver program to run ode45?
1 view (last 30 days)
Show older comments
Aaron Tytschkowski
on 18 Jun 2015
Commented: Aaron Tytschkowski
on 19 Jun 2015
This will probably be a glaring issue that I am missing. If I am trying to integrate from 0 to 0.115 why is my index coming back 0? Code is included below. I do not claim to be very good with MATLAB yet, either.
Solver:
function dydx = finPFR(x,y)
global beta gamma
dydx = zeros(2,1);
c = y(1);
T = y(2);
dydx(1) = -c*exp(gamma(1-(1/T)));
dydx(2) = c*beta*exp(gamma(1-(1/T)));
end
And the driver program:
global beta gamma
beta = 0.15;
gamma = 30;
xstep = [0:0.001:0.115];
yzero = [1 1];
[myx,myy] = ode45(@finPFR,xstep,yzero);
subplot(2,1,1)
plot(myx,myy(:,1,'k--'))
xlabel('VR/Q')
ylabel('Conversion')
subplot(2,1,2)
plot(myx,myy(:,2,'k-'))
xlabel('VR/Q')
ylabel('Temperature')
Errors:
>> run_finPFR
Attempted to access gamma(0); index must be a positive integer or
logical.
Error in finPFR (line 6)
dydx(1) = -c*exp(gamma(1-(1/T)));
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs,
odeFcn, ...
Error in run_finPFR (line 6)
[myx,myy] = ode45(@finPFR,xstep,yzero);
I know it's a long shot, but I have spent hours on this and can't seem to figure out where I am going wrong with the index. Any help would be appreciated!
2 Comments
Accepted Answer
Walter Roberson
on 18 Jun 2015
dydx(1) = -c*exp(gamma*(1-(1/T)));
dydx(2) = c*beta*exp(gamma*(1-(1/T)));
Note: using gamma as a variable is easily confused with the gamma function and so is not recommended.
5 Comments
Walter Roberson
on 19 Jun 2015
plot(myx,myy(:,1),'k--')
You had the ) in the wrong place and were trying to index myy by 'k--'
More Answers (0)
See Also
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!