MATLAB: How to find x for a given value of y

inputoutputxy

I'm stuck on this, and no one seems to understand the question. I've defined several variables and made x an array of values. I then made an anonymous function and used fplot to graph it's outputs(F in this case) for every x value. Now, I just need to find the x value that give me F=90. The only way I can think to do it is to solve for x by hand and then type that into matlab but there has to be a simpler way. Any body know how to do this? Here's up to where I'm stuck:
% Clear all windows and variables
clc
% Input the values for mass, height, friction coefficient, and gravity
m=18; % Mass (kilograms)
h=10; % Height (meters)
mu=0.55; % Friction coefficient (no units)
g=9.81; % Gravitational acceleration (m/s^2)
% Input a reasonable range for x
x=[-100:100];
% Calculate F given the range of x
F=@(x) (mu.*m.*g.*(h.^2 + x.^2).^(1/2))/(x+mu.*h);
% Plot F as a function of x
fplot(F,[0,100])
title('Force versus Distance')
xlabel('Distance (meters)')
ylabel('Force (newtons)')
grid on
% Find the x value that gives F=90
??????????????

Best Answer

Add this code to the bottom of your code:
Fx = (mu.*m.*g.*(h.^2 + x.^2).^(1/2)) ./ (x+mu.*h);
% Plot the function.
figure;
plot(x, Fx, 'b-');
grid on
% Find the x value that gives F=90.
% This happens when the difference between Fx and 90 is a minimum.
[difference, index_At_F_Equals_90] = min(abs(Fx-90))
% Get the x value at that index. Print to command window.
x90 = x(index_At_F_Equals_90)
Related Question