How can I find maximum of a function the function on MATLAB which has subject to rules?

4 次查看(过去 30 天)
I am trying to find the maximum of the function. My function is a nested function of 2 more functions.
My functions are formulas of charging vehicle system.
Function 1
ρ= ( λ)/mμ≤1
% Function to create Rho
function [rho] = RhoFn(lamda,m,mu)
if(m >= 0)
if (0<= lamda)&& (lamda<= 1)
rho = lamda / (m * mu);
le(rho,1);
Function 2
function [ result ] = p0(lamda,m, mu)
m1 = @mp1;
rm1 = m1(lamda,m,mu);
m3 = @mp3;
rm3 = m3(lamda,m,mu);
result = 1/(rm1 + rm3);
end
I created separate functions mp1 and mp3 so that p(0) = 1/mp1 + mp3 mp1 function :
function [mp] = mp1(lamda,m,mu )
% Part one of the Creation of P(0)
r = @RhoFn;
rho = r(lamda,m,mu);
f = factorial(m);
mp = ((m * rho)^m)/((1-rho)*f);
end
mp3 function is as follows:
function [ mp2 ] = mp3(lamda,m,mu )
% Part2 function for the creation of P(0)
%mp3 part function
r = @RhoFn;
rho = r(lamda,m,mu);
mp2=0;
for i=0:m-1
mp2 = mp2 + ((m*rho)^i)/factorial(i);
end
end
My main function is function 3 which is as follows:
function [ pkresult ] = pk( k,lamda,m,mu )
%P(k) Summary of this function goes here
% If and else Detailed explanation goes here
r = @RhoFn;
rho = r(lamda,m,mu);
p = @p0;
p0result = p(lamda,m,mu);
if k<m
pkresult = ((m*rho)^k/factorial(k))* p0result;
else
pkresult =(((m^m)*(rho^k))/factorial(m))* p0result;
end
end
By passing the values of lamda, mu, k and m I have to find maximum of my function 3 which is p(k). Which is subject has subject to conditions which are:
P (k<m) ≥ s
k, m ϵ N
s ϵ [0, 1]
How do I find maximum of my function using these subject to conditions?
  1 个评论
John D'Errico
John D'Errico 2015-5-12
编辑:John D'Errico 2015-5-12
It appears only to accept integer input. (It uses factorial, for example.) So it is NOT differentiable. fmincon will NOT work, nor will any tool that assumes smoothness in any form.

请先登录,再进行评论。

回答(1 个)

Alan Weiss
Alan Weiss 2015-5-12
Despite your many words, it is really not clear to me what your problem is.
  • What are the variables that you are given?
  • What are the variables that you can change to try to find a maximum?
  • What does this mean: I need to find Max(lamda,m) resolving the function using subject to?
  • What is the objective function (the thing that you are trying to maximize)? It looks like it might be P(k), but I am really not sure, especially because I do not know what P(0) means, and perhaps you really should be writing P(k,m,s).
  • What is the difference between p, the multiplier of m in the first case of the equation, and rho, the multiplier of m^k in the second case? Are they the same?
  • What is the meaning of P(k) and P(k < m)? Are these probabilities, so P(k < m) is the sum of P(j) for j from 1 to m - 1?
I suggest that you take the time to express yourself clearly. Can you boil the problem down to a single statement such as:
I have a function of three variables, P(k,m,s), where k is a positive integer, m is a positive integer, and s is a real variable between 0 and 1. My function is strictly positive and might be unimodal. Do you have any suggestions how I might find a maximum?
If that were indeed your question I would reply:
Take a mesh grid of values of k and m, say first try for each going from 1 to 100. Using these values, optimize your function over s between 0 and 1 using fmincon. Take the best feasible solution.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 个评论
Gollapinni Karthik
Gollapinni Karthik 2015-5-14
1) Basically I have three functions and function 1 is nested in function 2 and function 2 is nested in function 3. So it is like I am having one main function p(k) which calls function 1 and function 2 in it. My main funciton p(k) accepts variables k, lamda, m and mu. Where k and m are natural numbers or positive integers and lamda is a variable between 0 and 1 including 0,1 and mu can be any value as it is average time for my function.
2) The variables I can change are s and m.
3) I mean my function p(k) is the objective function for which I need to find the maximum which has subject to conditions. My objective function is p(k) only. I have to find maximum of that function which takes variables as inputs.
4) p(k) is the function and p(k<m) is the probability which is sum for k from 0 to 1.
p(k) function I have to find the maximum which has subject to constraints
p(k<m) >= 0,
s ϵ [0, 1]

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Design Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by