-1

Firstly, thank you very much in advance. I need to express a non-linear graph comprised (piecewise) of the following linear elements:

  • A line from $(x=0,y=100)$ to $(x=10,y=100.5)$
  • A line from $(x=10,y=100.5)$ to $(x=30,y=99.5)$
  • A line from $(x=30,y=99.5)$ to $(x=40,y=100.5)$

I need to implement this in a program I am writing in C++.

  • 1
    Can you write the equation of a straight line going through to points ? Later, you will use the equation if a block of IF/ELSE IF/..../END IF – Claude Leibovici Feb 08 '14 at 09:50
  • Please consider the people who will be reading your question and helping you. Try to format your question and use correct grammar so that it's very easy for people to read. No need to offer thanks 4 or 5 times. Once is sufficient, any more is clutter. – Amit Kumar Gupta Feb 08 '14 at 10:03
  • Heard of cubiic Splines? nurbs? – Narasimham Sep 21 '16 at 08:08

1 Answers1

0

Assuming you know how to compute $a$ and $b$ for a straight line $y=a+ b x$ foing through two points, you will end with something looking like

Y = 0.0
IF(X.GE.0.0.AND.X.LE.10.0) THEN
Y = 100.0 + 0.05 * X
ELSE IF(X.LT.30.0) THEN
Y = 101.0 - 0.05 * X
ELSE IF(X.LT.40.0) THEN
Y = 96.5 + 0.10 * X
ENDIF