How to initialize the values corresponding to the input argument of a function and use it in the following way as mentioned in the code

8 visualizzazioni (ultimi 30 giorni)
function [x_new, stageCost, unfeas, engTrq, emTrq] = hev(x, u, w, veh, fd, gb, eng, em, batt)
dt = 1; % s
%% Vehicle Model
% Wheels
% Wheel speed (rad/s)
wheelSpd = w{1} ./ veh.wh_radius;
% Wheel acceleration (rad/s^2)
wheelAcc = w{2} ./ veh.wh_radius;
% Tractive Force (N)
rolling_friction = veh.mass .* veh.gravity .* (veh.first_rrc + veh.second_rrc.*w{1});% how can we initialize the variables by using the input argument veh as mentioned in this equation
vehForce = (wheelSpd~=0) .* (rolling_friction + veh.aero_coeff.*w{1}.^2 + veh.mass.*w{2});
% Wheel torque (Nm)
wheelTrq = (vehForce .* veh.wh_radius + veh.axle_loss .* (wheelSpd~=0));

Risposte (1)

Lokesh
Lokesh il 20 Mar 2024
Hi Laxmi,
As per my understanding, you want to know how the variables are initialised using the input argument 'veh' as shown in the equation.
To initialize variables using the input argument 'veh', you essentially use the fields of the 'veh' structure to access specific parameters. The 'veh' argument is expected to be a structure with fields corresponding to various parameters such as 'wh_radius' , 'mass', 'gravity', 'first_rrc', 'second_rrc', 'aero_coeff', and 'axle_loss'.
Assuming the 'veh' structure is correctly passed to your function, it might look something like this:
%Random values are used for demonstration
veh = struct('wh_radius', 0.3, 'mass', 1500, 'gravity', 9.81, ...
'first_rrc', 0.015, 'second_rrc', 0.0005, 'aero_coeff', 0.3, ...
'axle_loss', 50);
To access a field of a structure in MATLAB, you use the dot (.) notation. For example, 'veh.wh_radius' accesses the 'wh_radius' field of the 'veh' structure. Once you have accessed the necessary fields, you can directly use these variables in your equations, such as for rolling friction:
rolling_friction = veh.mass .* veh.gravity .* (veh.first_rrc + veh.second_rrc.*w{1});
In this equation, 'veh.mass', 'veh.gravity', 'veh.first_rrc', and 'veh.second_rrc' are all parameters accessed from the 'veh' structure.
Please refer to the following documentation to know more about 'struct' in MATLAB:

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by