Finding points on a line from user input
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The question is as follows: 'Make a function file “e82.m” with 5 input parameters. The first four are two pairs of xand y- coordinates (x1, y1, x2, y2 ) and the fifth, a single x-value. The first four are two dots in a y-x plot. Connect these with a line and the fifth value is also a dot on the same line, but you should find out the corresponding y-value and present everything in a plot. Of course the five parameters must be chosen to be arbitrary.'
so far I have this: xvalueone = 'x value between 0 and 10'; xvalue = input(xvalueone); a=xvalue/10
yvalueone = 'y value between 0 and 10'; yvalue = input(yvalueone); b=yvalue/10
xvaluetwo = 'second x value between 0 and 10'; xvalue = input(xvaluetwo); c=xvalue/10
yvaluetwo = 'second y value between 0 and 10'; yvalue = input(yvaluetwo); d=yvalue/10
A=[a,c] B=[b,d]
plot(A,B,'-')
input ('select x value between the previous two values')
BUT I don't know how to get the corresponding value from the line.
Thanks for any help
0 commentaires
Réponse acceptée
Image Analyst
le 15 Juin 2013
Use the equation of a line y = m*x+b. m is the slope and is (y2-y1)/(x2-x1). b is the offset and I'm sure you can figure that out because this is just 8th grade algebra. If you can't, you can just use polyfit to tell you.
coeffs = polyfit([x1, x2], [y1, y2], 1)
So then you know m, and b, and you just plug in the x and you get the y - it's trivial.
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!