How do I optimize solutions of ODE?
5 views (last 30 days)
Show older comments
I'm trying to follow the process below. I would appreciate if you could let me know how to do this.
① solve the ODE which includes an optimization variable.
② optimize the objective function, which is the solution of ODE at a particular point.
I also post the code I wrote. I think the ODE needs to be converted in some way, but I don't know how.
c = optimvar("c","LowerBound",0,"UpperBound",100);
Fc = 10;
M = @(t,Y)[Y(2);sign(Y(2)).*(-1.0./3.0e+1).*Fc-Y(1).*1.048982544e+3-Y(2)./3.0e+1.*c]; %ODE
interval=[0:0.001:0.5];
yinit=[0.008337,0];
[t,y] = ode45(M,interval,yinit);
prob = optimproblem;
prob.Objective = 0.00592708-y(1,194); %objective function
c0.c = 0;
sol = solve(prob,c0)
0 Comments
Accepted Answer
Sam Chak
on 3 Apr 2024
Edited: Sam Chak
on 3 Apr 2024
Considering your objective of varying the force input 'Fc', it becomes necessary to create a Gain Schedule for the damping coefficient 'c' as a function of the force. Through a simple trial-and-error approach, it appears that a linear function for the damping coefficient c can yield relatively satisfactory results.
Please take a look at the Gain Schedule provided below:
format long
%% Gain Schedule for damping coefficient c
c = @(Fc) 105.030559597794 - 5.54966340482472*Fc;
force = linspace(5, 15, 201);
plot(force, c(force)), grid on
xlabel('Force'), ylabel('c'), title('Gain Schedule for damping coefficient c')
%% 2nd-order ODE
Fc = 8; % Force input
M = @(t,Y) [Y(2);
sign(Y(2))*(- 1.0/3.0e+1)*Fc - Y(1)*1.048982544e+3 - Y(2)/3.0e+1*c(Fc)];
%% call ode45 solver
interval= [0:0.001:0.5];
yinit = [0.008337, 0];
[t, y] = ode45(M, interval, yinit);
%% plot results
out = y(:,1);
[pks, locs] = findpeaks(out)
idx = locs(1);
plot(t, out), hold on
plot(t(idx), out(idx), 'o', 'markersize', 12), grid on
xlabel('t'), ylabel('y(t)'), title('Response and Desired Peak')
legend('Response', 'Desired Peak')
10 Comments
Sam Chak
on 3 Apr 2024
You are welcome, @Amito Usami. It's important to note that this approach is known as Gain-scheduling. It is quite similar to creating a lookup table with an adequate number of data points and subsequently interpolating the data using the curve-fitting method.
More Answers (0)
See Also
Categories
Find more on Surrogate Optimization 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!

