Attempted to access sym(67); index out of bounds because numel(sym)=2. trying to solve matrix multiple Eqns

Below is my code l m newbie in matlab, spent 3 days trying to figure this out, please tell what l m doing wrong
filename='DriveCyclesCP.xlsx';
V=xlsread('DriveCyclesCP.xlsx',2,'C9:C774'); % Get the velocity values, they are in an array V.
N=length(V); % Find out how many readings
mass = 1700 ; % Vehicle mass+ two 70 kg passengers.
area_Cd = 0.75; % Frontal area in square metres
Crr=0.009; %rolling resistance
g=9.8; % gravity acceleration
T=774; %UDDS cycle time duration
V_ave = 21.5; % UDDS avearage speed im m/s
rd=0.3; % Effective tire radius
Qhv =12.22; % E85 low Heating value in kWh/kg
Vd = 2.189; % engine size in L
md=0.801; % mass density of Ethanol
mf =Vd*md; % mf is the fuel mass consumed per cycle
Per = zeros(1,N); % engine power for each point of the drive cycle
a = zeros(1,N); % acceleration
SFC = zeros(1,N); % specific fuel consumption
Wc = zeros (1,N); % mass flow rate
nf = zeros (1,N); %fuel efficiency
Pm = zeros (1,N); % motor power
Pt = zeros (1,N);
Te =zeros (1,N); % Engine Troque
Tt = zeros (1,N);
Tm =zeros (1,N);
we =zeros (1,N); % Engine rot speed
wt = zeros (1,N);
wm =zeros (1,N);
S =zeros (1,8);
int (sym ('C'));
for C=1:N
a(C)=V(C+1)-V(C);
Pt(C)= V(C)*(mass*g*Crr + (0.5*area_Cd*1.202*(V(C))^2) + mass*a(C))/1000;
Per(C)=(mass*g*Crr +0.5*area_Cd*1.202*(V(C))^2 +mass*g*0.03)/1000*0.85;% e
syms Te(C) Tt(C) Tm(C) wt(C) we(C) wm(C) k1 k2
S = solve( Pm(C)==Pt(C) - Per(C), Tt(C)*wt(C)== Pt(C), Tt(C)*wt(C)== Te(C)*we(C) + Tm(C)*wm(C), wt(C)==we(C)/k1, wt(C)==wm(C)/k2, Pm(C)==wm(C) *Tm(C), Per(C)==we(C) *Te(C), Tt == k1*Te + k2*Tm );

Answers (2)

Your line
int (sym ('C'));
could fail if you do not have the symbolic toolbox.
It is not going to be useful even if you do have the symbolic toolbox, as it would be a request to integrate C, and then throw away the result. It would not be an indication that C is to be an integer.
Note that
syms Te(C) Tt(C) Tm(C) wt(C) we(C) wm(C) k1 k2
would try to request that Te be treated as a function with parameter C. What you appear to be looking for is indexing.
You have declared a bunch of variables as numeric zeroes and then you declare the same names as symbols. But you never assign anything to the names after you initialize them.
You have also not indicated which variables you are trying to solve for in the solve() call. solve() does not "look back" at the "syms" call right before it.
Notice too that your final equation Tt == k1*Te + k2*Tm is not written consistently with the rest.
What I would do would be something like,
for C = 1 : N
solutions = solve(expressions without subscripts and using slightly different names, list of the names to solve for)
Te(C) = solutions.te; %slightly different name
Tt(C) = solutions.tt; %slightly different name
and so on
end

This question is closed.

Products

Asked:

on 1 Dec 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!