Clear Filters
Clear Filters

Finding Corresponding X Value for Y value

2 views (last 30 days)
Looking to find the corresponding X value for the maximum force P in my force vs. displacement graph.
P=zeros(1,750);
theta=zeros(1,750);
L=zeros(1,750);
F=zeros(1,750);
W=10;
g=9806;
for x = 1:750
theta(x)=atand(400/x);
L(x)=sqrt((x^2)+(400^2));
F(x)=W*g*cosd(theta(x))*500;
P(x)=F(x)/L(x);
end
plot(1:750,P)
xlabel('x in mm')
ylabel('P in kg/mm/s^2')
Pmax= max(P);
fprintf('The maximum P value in kg/mm/s^2 is: %0.2f \n',Pmax);

Accepted Answer

Les Beckham
Les Beckham on 21 Feb 2022
Edited: Les Beckham on 21 Feb 2022
If you ask for two outputs from the max() function you can find the index of your peak:
P=zeros(1,750);
theta=zeros(1,750);
L=zeros(1,750);
F=zeros(1,750);
W=10;
g=9806;
for x = 1:750
theta(x)=atand(400/x);
L(x)=sqrt((x^2)+(400^2));
F(x)=W*g*cosd(theta(x))*500;
P(x)=F(x)/L(x);
end
plot(1:750,P)
xlabel('x in mm')
ylabel('P in kg/mm/s^2')
[Pmax, index] = max(P);
fprintf('The maximum P value in kg/mm/s^2 is: %0.2f at x = %d mm\n', Pmax, index);
The maximum P value in kg/mm/s^2 is: 61287.50 at x = 400 mm

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!