MATLAB Answers

0

Getting a smooth curve instead of two linear functions

Asked by Arbër Lladrovci on 17 May 2019 at 23:36
Latest activity Edited by John D'Errico
on 18 May 2019 at 9:07
So, I got this figure as a part of a physics problem, with two intersecting linear functions and due to an extra restriction, only the left side of the intersection makes physical sense. I would like to have a smooth curve that connects the points on the graph, so, I would like to join them with a smooth curve. The functions are y1 = -x+4.4735 and y2=1.42x-9.09. In other words, I'm asking how to make a stencil that connects these dots smmothly?

  1 Comment

Arbër Lladrovci’s Comment to my Answer clarifying the Question moved here —
I know, that technically the graph is correct, but I would like a smother transition between the two lines, I guess my question is similar to this https://stackoverflow.com/questions/43063157/forming-a-curve-between-two-lines but being a beginner I'm unable to understand the code there
(I deleted my Answer because I cannot solve this.)

Sign in to comment.

1 Answer

Answer by John D'Errico
on 18 May 2019 at 9:05
Edited by John D'Errico
on 18 May 2019 at 9:07

You have two lines that create what is NOT a function, in the sense that it is single valued. So, for any x, you get a y out. Here, for some values of x, you would get two values of y, and for other values of x, you get no values for y. At one point, there is a single solution. Sorry, but that is not a function that can be evaluated properly. As such, you cannot use standard interpolation tools for this. They are designed to work with single valued relationships, and you don't have that.
There are viable solutions available, but you need to accept that compromise must always exist. So, if you want a curve that passes through what might be 3 nonlinearly shaped points, then it will NOT be a LINEAR curve! And once you accept that the result will not be composed of straight lines, then you must also accept that it will deviate in ways that are potentially significantly different from straight lines. Is the result allowed to miss that corner? If it does pass through the intersection point exactly, AND be smooth, then it will probably belly out a lot. So, what are you willing to give up? What shape would you draw by hand?
Next, again, the result will not be a function of the form y = f(x). That does not exist. What can be done here, is to swap the relationship into one of the form x = f(y). Once you do that, then you can create a functional form.
Finally, those lines go on forever to the left. They are essentially rays, or half lines, intersecting at one point, but going to minus infinity along both of those half lines. Do you want something that can return a point for x at y=-100 pr at y=+100? Or are you just asking for a smooth curve of some ilk?
I might draw a picture, but in order to do even that, I need to know how far those lines extend. You do not have three points. You have two half-lines. (In order for this to be a question about MATLAB, I'll use MATLAB here.) They intersect at:
syms x y
y1 = y == -x+4.4735;
y2 = y == 1.42*x-9.09;
[xint,yint] = solve(y1,y2);
[vpa(xint),vpa(yint)]
ans =
[ 5.6047520661157024793388429752066, -1.1312520661157024793388429752066]
The intersection happens around the (x,y) pair (5.60475, -1.13125).
But do the lines stop at x (or log(E)) around roughly x=3.5? How far out is minus infinity? And where would you have those lines no longer be linear?
vpa(subs(y1,x,3.5))
ans =
y == 0.9735
vpa(subs(y2,x,3.5))
ans =
y == -4.12
So, before I try to answer this question in any serious way, I would need to know the answer to all of those questions. What exactly are you looking to see as a result? Just a "smooth" curve that passes through the xy pairs:
[3.5, -4.12]
[5.60475, -1.13125]
[3.5, 0.9375]
Or what? What deviation from those lines is acceptable? How far to the left do those lines extend?

  0 Comments

Sign in to comment.