eqn1 = 
Create similar curves through specific data points
Show older comments
Hi,
I have the following curve in green which can be created by using the data point in the attachment.
I want to create similar shaped curves where each of them runs through the two fixed data points at P1(0/0) and P2 (-31.5,30) but with a slight offset to each other. So all curves basically cross each other and start at P1 and rund through P2. I understand that in theory there are unlimited options. How would you do that?

Accepted Answer
More Answers (2)
x1 = -23;
y1 = 28;
x2 = -12;
syms y2
x3 = 0;
y3 = 0;
syms a b c
eqn1 = a*x1^2 + b*x1 + c == y1
eqn2 = a*x2^2 + b*x2 + c == y2
eqn3 = a*x3^2 + b*x3 + c == y3
sol = solve([eqn1, eqn2, eqn3], [a, b, c])
syms x
eqn = expand(subs(a*x^2 + b*x + c, sol))
fsurf(eqn, [-10 10 -10 10])
John D'Errico
on 3 Mar 2025
Edited: John D'Errico
on 3 Mar 2025
You have asked a confusing question, which usually means you are yourself confused, perhaps about what you really want to do. It is hard to know. But, the basics of your question are easy enough to answer.
You have given two points, (0,0), and (-31.5,30). How many points determine a line? TWO. The slope of that line is deltay/deltax.
slope = (30-0)/(-31.5 - 0)
And the equation of that line is geven by the old point-slope form we should have learned a few millenia ago. Well, I did. Maybe not quite that long though. Since one of the points the line must pass through is (0,0), that gives us:
y-0 = slope*(x-0)
or
y = -30/31.5*x
that line passes through the two points.
Now, you can add a new term to that functional form that will stoll pass through the same points, as long as the new form has a root at BOTH x=0, and at x=-31.5. What does that mean? ANYTHING that looks like this will suffice:
a*x*(x+31.5)
If a is negative, the curve will lie above the straight line between those points. positive values of a will fall below the line. TRY IT!
yquad = @(x,a) -30/31.5*x + a*x.*(x+31.5);
fplot(@(x) yquad(x,0),[-31.5,0],'g-')
hold on
fplot(@(x) yquad(x,0.025),[-31.5,0],'r-')
fplot(@(x) yquad(x,-0.025),[-31.5,0],'b-')
fplot(@(x) yquad(x,-0.01),[-31.5,0],'k-')
hold off
grid on
legend('a = 0 (straight line)','a = 0.025','a = -0.025','a = -0.01')
You can be more creative yet, in fact, infinitely so, as long as the extra terms are zero at those two points.
Since we don't really know your goals in this, it is impossible to go much further though. If I had to make a wild guess, it would be that you hve some data, and you want to fit such a curve through the data that passes through those points. The simple solution is to use what I suggested, estimating the value of a. You could also add extra (higher order) terms that have the same properties, but different shapes. The tools to fit such a curve would be regression tools, perhaps fit, or lsqnonlin, lsqcurvefit, nlinfit, etc.
1 Comment
Konvictus177
on 4 Mar 2025
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





