How can I find the value of y given x using matlab / octave

1,246

Yes, let's first find the equation of the line

Notice, the equation of the line passing through the points: $(40, 5)$ & $(50, 1)$ is given as $$y-5=\frac{5-1}{40-50}(x-40)$$ $$y-5=\frac{-2}{5}(x-40)$$ Now, setting $x=42.5$, we get y-coordinate $$y-5=\frac{-2}{5}(42.5-40)$$ $$y=-\frac{2}{5}(2.5)+5$$$$=5-1=4$$ $$\bbox[5px, border:2px solid #C0A000]{\color{red}{y=4}}$$

Share:
1,246

Related videos on Youtube

Rick T
Author by

Rick T

Updated on August 07, 2020

Comments

  • Rick T
    Rick T over 3 years

    I have two points on a plot point1=(40,5) and point2=(50,1)

    How can I find the value of y given x=42.5 I know y is 4 by looking at the plot but is there away to calculate the y value directly.

    I found the slope: y2-y1/x2-x1 (1-5)/(50-40) =-0.4

    Example: matlab code:

    clf reset
    pts=[40,5;50,1] %x-y points
    slope=(pts(2,2)-pts(1,2))/(pts(2,1)-pts(1,1)); %slope
    plot(pts(:,1),pts(:,2),'-b') %plot line
    hold on
    plot(pts(:,1),pts(:,2),'r*') %plot points with stars
    

    Image

    PS: I'm using octave 3.8.1 which is like matlab