Filter löschen
Filter löschen

Need to flip a function and pass it through fminbnd to get the max, function has multiple agruements

1 Ansicht (letzte 30 Tage)
I'm trying to use fminbnd to find the max value of a function that has multiple arguements. I know I need to flip the function so the max becomes the minimum, but I can't seem to get the syntax for it, I can't even pass the function through correctly without flipping it.
v0 = 20;
th0 = 45;
h0 = 5;
g = 9.81;
t = linspace(0,4,400);
max = fminbnd(height(t,v0,th0,h0)*(-1),0,4)
%%-----------------------
function [x,y,vx,vy] = trajectory(t,v0,th0,h0,g)
if nargin<=4, g = 9.81; end
if nargin<=3, h0 = 0; end
if nargin==2, th0 = 90; end
th0 = th0*pi/180;
x = v0*cos(th0)*t;
y = h0 + v0*sin(th0)*t - 1/2*g*t.^2;
vx = v0*cos(th0);
vy = v0*sin(th0) - g*t;
%%-------------------------
function y = height(t,v0,th0,h0)
[x,y] = trajectory(t,v0,th0,h0);

Akzeptierte Antwort

D
D am 16 Okt. 2011
Found the solution with the following code:
tmax = fminbnd(@(t) height(t,v0,th0,h0)*(-1),0,4);
hmax = height(tmax,v0,th0,h0);

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by