Minimising a non lineair function with constraints
Show older comments
As a novice to Matlab, I am having great difficulty with the simplest of things. My problem is a bit complicated but bear with me.
My program is supposed to do the following: It has to display a curve of power (P) which corresponds to a hydrogen usage of a fuel cell. What it should do is 1) display the curve of P,Q curve 2) calculate a velocity so that the hydrogen usage is minimal.
In order to do that I came up with this:
P (power) = F (force is a known value) * v (velocity) P / F = v
It should vary the power so it calculates the corresponding hydrogen usage. This value is then used for the velocity. It plays with the power until it finds the minimal hydrogen usage and the minimal velocity to achieve that. My current code is like this:
function hydrogenusage
P = 0:1:4000;
Q= (120*P)-(P.^2);
plot(P,Q)
xlabel('Power')
ylabel('Usage')
title('Hydrogen usage')
axis([0 120 0 4000])
grid on
end
In this basic function with the current formula, there are at max only two solutions for P. That's okay.
But how do I make the program vary the power P so that it looks for the minimal Q? And if this is realised, it should return to me a value of v = 0 so that Q = 0. Therefore I want to add a simpel line with 0 < P > 2000.
How can I make it search for the minimal hydrogen usage Q while having a minimum value constraint on it whilst also giving me a value for v? I know Matlab has a function called 'fmincon' which does just that, but I have no idea how to use it here.
If you want to make suggestions but don't know the right numbers: my numbers are entirely arbitrary: they have no value whatsoever and do not reflect the real thing.
Accepted Answer
More Answers (0)
Categories
Find more on Electromechanical 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!