Index in position 2 exceeds array bounds (Index must not exceed 1) errors?
Show older comments
% Code to solve system of four simultaneous differential equation
clc
N0 = [9.66e17;0;0;0]; % Intital conditions of N1, N2, N3, N4 (9.66e17,0,0,0)
[T, N] = ode15s(@rate_eq,[0 126e-15], N0); % Intital conditions of time from 0 to 126e-15
plot(T,N(:,4),T,N(:,3),T,N(:,2),T,N(:,1)) % Plotting of N1 N2 N3 N4 vs Time
function dN = rate_eq( t,N )
t = 126e-15;
W = [0.2716 0.4243 0.6110 0.8317 1.0862 1.3748 1.6972]*1e9;
PION = [0.7072 0.8874 1.0254 1.2375 1.4143 1.5911 1.7679]*1e11;
dN = zeros(4,7); % Blank array to store N1 N2 N3 N4 from solution for each values of seven values of W and PION
Q = 10e10; % Constant value
A = 10e8; % Constant value
Ppd = 10e10; % Constant value
% W and PION is not constant and its values are calculated in first part of
% code using FOR loop
for j = 1:length(W)
dN(1,j) = (-W(j)*N(1,j)) + ((Q+A)*N(2,j)) + ((W(j)+Q+A)*N(3,j)) + 0; % first equation
dN(2,j) = 0 + (-(Q+A)*N(2,j)) + ((Q+A)*N(3,j)) + 0; % second equation
dN(3,j) = (W(j)*N(1,j)) + 0 - (W(j)+(2*Q)+(2*A)+ Ppd + PION(j))*N(3,j) + 0; % third equation
dN(4,j) = 0 + 0 + PION(j)*N(3,j) + 0; % fourth equation
end
end
%-----------end of code----------------
I want to store values of N1 N2 N3 N4 for each seven different values of W and PION.
I also want to plot N1 N2 N3 N4 vs time for each W and PION.
But I am getting the following errors:
Index in position 2 exceeds array bounds. Index must not exceed 1.
Error in test_soln_rate>rate_eq (line 24)
dN(1,j) = (-W(j)*N(1,j)) + ((Q+A)*N(2,j)) + ((W(j)+Q+A)*N(3,j)) + 0; % first equation
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 148)
odearguments(odeIsFuncHandle, odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in test_soln_rate (line 6)
[T, N] = ode15s(@rate_eq,[0 126e-15], N0); % Intital conditions of time from 0 to 126e-15
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics 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!









