How to find the max value of a function with two variables

14 views (last 30 days)
x = linspace(-90,.1,90); %Theta 1
y = linspace(-90,.1,90); %Theta 2
cx = -2.598.*cos(x)-1.5.*sin(x)-.525.*cos(y)-.3977.*sin(y);
cy = -2.598.*sin(x).*sin(y)+1.5.*cos(x).*sin(y)-.2227.*sin(y)+.525;
cz = -2.598.*sin(x).*cos(y)+1.5.*cos(x).*cos(y)-.3977+.2227.*cos(y);
v = sqrt(cx.^2+cy.^2+cz.^2); %Equation for finding impact velocity
where v is a function of x and y
I need to find the maximum value of the function v, and the values of x and y that correspond to the max.
Thanks, Connor

Accepted Answer

Star Strider
Star Strider on 19 Sep 2018
This seems to work:
idx = find(v == max(v(:))); % Index Of Maximum ‘v’
Then to test to see if the corresponding elements produce the maximum value of ‘v’:
vm = sqrt(cx(idx).^2+cy(idx).^2+cz(idx).^2); % Test With Elements
test = v(idx) == vm
and the result of ‘test’ is 1 or true. The corresponding elements are those with the same positions of ‘idx’.

More Answers (0)

Categories

Find more on Oceanography and Hydrology 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!