Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/fmincon with simulink model

fmincon with simulink model

PuTI / 2025-01-29
fmincon with simulink model
Matlab News

Hello, I’m struggling with fmincon, as I’m still a beginner. I have a Simulink model that simulates the behavior of an electric vehicle and a track specification (maximum speed in different sections, total length).
The model takes as input the throttle and brake pedal pressures (steering is not relevant in this case) and outputs various vehicle dynamics parameters such as speed, jerk, acceleration, and SoC.
My goal is to determine the optimal pedal usage to complete the track while maximizing the remaining SoC, using the results obtained from the model.
I wrote a MATLAB script for this, but the throttle and brake pedal vectors never change—they always remain the same as the initial values u0 that I provide.
Does anyone know what might be causing this issue?

My cost function is:
function [cost, c, ceq] = myCostAndConstraints(u, timeVec, steeringTS, w1, w2, w3, w4, w5, total_distance)
N = length(u)/2;
throttleProfile = u(1:N);
brakeProfile = u(N+1:end);

myThrottleTs = timeseries(throttleProfile, timeVec);
myBrakeTs = timeseries(brakeProfile, timeVec);

in = Simulink.SimulationInput(‘optimization_offline_model’);
in = in.setVariable(‘myThrottleTs’, myThrottleTs);
in = in.setVariable(‘myBrakeTs’, myBrakeTs);
in = in.setVariable(‘steeringWheelAngle_ts’, steeringTS);

try
simOut = sim(in);
catch ME
warning("Simulation error: %s" + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end

try
timeSim = simOut.tout;
speedData = simOut.v_z.Data;
SoCData = simOut.SoC.Data;
jerkData = simOut.j_z.Data;
distanceData = simOut.distance.Data;
catch ME
warning("Error extracting signals: " + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end

SoC_final = SoCData(end);
time_elapsed = timeSim(end);
distance_final = distanceData(end);

penalty = 0;

if any(SoCData < 0.2)
penalty = penalty + w1 * (0.2 – min(SoCData(SoCData<0.2)));
end

vLimHard = 41.5;
violV = speedData – vLimHard;
violV(violV<0) = 0;
if any(violV > 0)
penalty = penalty + w5 * sum(violV);
end

avgJerk = mean(jerkData);
maxJerk = max(abs(jerkData));
penalty = penalty + w3*(max(0, 0.2 – avgJerk))^2 + w3*(max(0, avgJerk – 0.7))^2;
if avgJerk > 0.6
penalty = penalty + w3*(avgJerk – 0.6);
end
if maxJerk > 0.9
penalty = penalty + w3*(maxJerk – 0.9);
end

cost = – w1*SoC_final + w2*(time_elapsed) + w4 * abs(total_distance – distance_final) + penalty;
disp("Cost function =" + cost);

vLimVec = getVelocityLimit(distanceData, vLimHard);
c = speedData – vLimVec;
ceq = throttleProfile .* brakeProfile;
endHello, I’m struggling with fmincon, as I’m still a beginner. I have a Simulink model that simulates the behavior of an electric vehicle and a track specification (maximum speed in different sections, total length).
The model takes as input the throttle and brake pedal pressures (steering is not relevant in this case) and outputs various vehicle dynamics parameters such as speed, jerk, acceleration, and SoC.
My goal is to determine the optimal pedal usage to complete the track while maximizing the remaining SoC, using the results obtained from the model.
I wrote a MATLAB script for this, but the throttle and brake pedal vectors never change—they always remain the same as the initial values u0 that I provide.
Does anyone know what might be causing this issue?

My cost function is:
function [cost, c, ceq] = myCostAndConstraints(u, timeVec, steeringTS, w1, w2, w3, w4, w5, total_distance)
N = length(u)/2;
throttleProfile = u(1:N);
brakeProfile = u(N+1:end);

myThrottleTs = timeseries(throttleProfile, timeVec);
myBrakeTs = timeseries(brakeProfile, timeVec);

in = Simulink.SimulationInput(‘optimization_offline_model’);
in = in.setVariable(‘myThrottleTs’, myThrottleTs);
in = in.setVariable(‘myBrakeTs’, myBrakeTs);
in = in.setVariable(‘steeringWheelAngle_ts’, steeringTS);

try
simOut = sim(in);
catch ME
warning("Simulation error: %s" + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end

try
timeSim = simOut.tout;
speedData = simOut.v_z.Data;
SoCData = simOut.SoC.Data;
jerkData = simOut.j_z.Data;
distanceData = simOut.distance.Data;
catch ME
warning("Error extracting signals: " + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end

SoC_final = SoCData(end);
time_elapsed = timeSim(end);
distance_final = distanceData(end);

penalty = 0;

if any(SoCData < 0.2)
penalty = penalty + w1 * (0.2 – min(SoCData(SoCData<0.2)));
end

vLimHard = 41.5;
violV = speedData – vLimHard;
violV(violV<0) = 0;
if any(violV > 0)
penalty = penalty + w5 * sum(violV);
end

avgJerk = mean(jerkData);
maxJerk = max(abs(jerkData));
penalty = penalty + w3*(max(0, 0.2 – avgJerk))^2 + w3*(max(0, avgJerk – 0.7))^2;
if avgJerk > 0.6
penalty = penalty + w3*(avgJerk – 0.6);
end
if maxJerk > 0.9
penalty = penalty + w3*(maxJerk – 0.9);
end

cost = – w1*SoC_final + w2*(time_elapsed) + w4 * abs(total_distance – distance_final) + penalty;
disp("Cost function =" + cost);

vLimVec = getVelocityLimit(distanceData, vLimHard);
c = speedData – vLimVec;
ceq = throttleProfile .* brakeProfile;
end Hello, I’m struggling with fmincon, as I’m still a beginner. I have a Simulink model that simulates the behavior of an electric vehicle and a track specification (maximum speed in different sections, total length).
The model takes as input the throttle and brake pedal pressures (steering is not relevant in this case) and outputs various vehicle dynamics parameters such as speed, jerk, acceleration, and SoC.
My goal is to determine the optimal pedal usage to complete the track while maximizing the remaining SoC, using the results obtained from the model.
I wrote a MATLAB script for this, but the throttle and brake pedal vectors never change—they always remain the same as the initial values u0 that I provide.
Does anyone know what might be causing this issue?

My cost function is:
function [cost, c, ceq] = myCostAndConstraints(u, timeVec, steeringTS, w1, w2, w3, w4, w5, total_distance)
N = length(u)/2;
throttleProfile = u(1:N);
brakeProfile = u(N+1:end);

myThrottleTs = timeseries(throttleProfile, timeVec);
myBrakeTs = timeseries(brakeProfile, timeVec);

in = Simulink.SimulationInput(‘optimization_offline_model’);
in = in.setVariable(‘myThrottleTs’, myThrottleTs);
in = in.setVariable(‘myBrakeTs’, myBrakeTs);
in = in.setVariable(‘steeringWheelAngle_ts’, steeringTS);

try
simOut = sim(in);
catch ME
warning("Simulation error: %s" + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end

try
timeSim = simOut.tout;
speedData = simOut.v_z.Data;
SoCData = simOut.SoC.Data;
jerkData = simOut.j_z.Data;
distanceData = simOut.distance.Data;
catch ME
warning("Error extracting signals: " + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end

SoC_final = SoCData(end);
time_elapsed = timeSim(end);
distance_final = distanceData(end);

penalty = 0;

if any(SoCData < 0.2)
penalty = penalty + w1 * (0.2 – min(SoCData(SoCData<0.2)));
end

vLimHard = 41.5;
violV = speedData – vLimHard;
violV(violV<0) = 0;
if any(violV > 0)
penalty = penalty + w5 * sum(violV);
end

avgJerk = mean(jerkData);
maxJerk = max(abs(jerkData));
penalty = penalty + w3*(max(0, 0.2 – avgJerk))^2 + w3*(max(0, avgJerk – 0.7))^2;
if avgJerk > 0.6
penalty = penalty + w3*(avgJerk – 0.6);
end
if maxJerk > 0.9
penalty = penalty + w3*(maxJerk – 0.9);
end

cost = – w1*SoC_final + w2*(time_elapsed) + w4 * abs(total_distance – distance_final) + penalty;
disp("Cost function =" + cost);

vLimVec = getVelocityLimit(distanceData, vLimHard);
c = speedData – vLimVec;
ceq = throttleProfile .* brakeProfile;
end fmincon, simulink MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Warning: Error updating FunctionLine in using fplot
2025-05-12

Warning: Error updating FunctionLine in using fplot

Solid creation Simulink, simscape multibody: stuck in loading
2025-05-12

Solid creation Simulink, simscape multibody: stuck in loading

Does Matlab 2023b support Classification learner like what I got trainned in ML Module?
2025-05-12

Does Matlab 2023b support Classification learner like what I got trainned in ML Module?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss