Calling function in fminsearch
Show older comments
I want to call a function lamda to update initial value in fminsearch.
The initial value of lambda(1) =-1.
I want to update in lambda as lambda(i+1)=lambda(i)-0.01*(lambda(end)).
This computation of lambda should continue until lambda(end) < 0.01. I am not able to call function in fminsearch as FMINSEARCH accepts inputs only of data type double.
close all
clear all
clc
[optimal_lambda,cost] = fminsearch(@cost_lambda, @lamda)
a = optimal_lambda(1)
function cost = cost_lambda(lambda)
part_a = @(t,y)[-0.02*y(1); (y(2)/0.8)*(1/0.8)*exp(0.01*t)];
[t,y]=ode45(part_a, [0 10], [0.5,-1]');
cost = (1-(1/0.01)*(1-exp(-log((-1+(y(1)/0.8)^2)/(0.015*lambda(1)*exp(0.01*t)))))*(1-(y(1)/0.8))^2);
function lambda = lamda(lambda)
lambda(1)=-1;
i=1;
for lambda(end)<0.01
lambda(i+1)=lambda(i)-0.01*lambda(end)
i=i++
end
end
end
Accepted Answer
More Answers (0)
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!