필터 지우기
필터 지우기

intersection of a line y=ax+b with a matrix containing x and y

조회 수: 3 (최근 30일)
Mary
Mary 2021년 1월 2일
댓글: Mary 2021년 1월 3일
Dear Matlab users,
What I want to do is very simple. I am wondering if there is already a function in Matlab written for it. I explain the idea:
I have two vectors: vec_x and vec_y. At the other hand, I have a line which is described as y=ax+b
I want to find the intersection between this line y=ax+b with the set of vectors vec_x and vec_y. And lets asuume that to keep the accuracy as high as possible, we dont want to find a polynomial function which links vec_x to vec_y.
Below, I give a very simple example:
vec_x=[1 2 3]; vec_y= [1 2 3];
and the line is y=5x-10;
so I would start by replacing all the values of vec_x in the line to see if any of vec_y is obtaind. If this step fails that means I shoud creat a new vec_x_new= 1:step:3, and make an interpolation to find vec_y_new (vec_y_new=interp1(vec_x, vec_y, vec_x_new). So I keep changing the "step", till I found that for vec_x_new(i)=2.5 -> y=a vec_x_new(i) + b = 2.5; and 2.5 = vec_y_new(i)
So, now the question is whether this idea already exists in terms of a function in Matlab.
Thanks a lot for your help,
Best regards,
Mary
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2021년 1월 2일
hello Mary
there are maybe some already good code for what you intend to do
Mary
Mary 2021년 1월 3일
thanks Mathieu. I think indeed, fzero should be used.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2021년 1월 2일
편집: Matt J 2021년 1월 2일
x_intersection = fzero(@(x) a*x+b-interp1(vec_x,vec_y,x) , vec_x([1,end]) )

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by