How do I use a general equation form as a function that calculates my data points of x and y? Essentially, I am trying to use the vernal form equation to calculate conduction velocity from diameter and a single parameter. I have the data imported, but do not know how to utilize the general form equation in Mathematica.

  • 2
    $\begingroup$ You will greatly increase your chances of getting help here if you were to put more effort into your question. If you have code that is not giving the results you want, show the code and describe exactly what you expected to get but didn't. If you don't know how to start coding what you want, describe your problem carefully in words giving the full set of inputs you would provide and what output you expect to get back. $\endgroup$ – m_goldberg Sep 10 at 5:35
  • 1
    $\begingroup$ What is the "vernal form equation", what is "conduction velocity", what is a "single parameter"? Is your data in {...,{x,y},...} form? $\endgroup$ – yarchik Sep 10 at 8:41
  • $\begingroup$ I do not know where to start with the code. $\endgroup$ – Mary Sep 10 at 13:23
  • $\begingroup$ The "General Form" of the equation of a straight line is: Ax + By + C = 0. $\endgroup$ – Mary Sep 10 at 13:24
  • $\begingroup$ Are you trying to fit a straight line to your data points? If so, take a look at LinearModelFit. $\endgroup$ – Rohit Namjoshi Sep 11 at 12:38

Do I understand your problem correctly: You have an implicit function of x and y: fu[x,y] == 0 that you can not solve for y. And you want to fit data in the form {{x1,y1},{x2,y2},..} to this implicit function.

First, if possible, you may eliminate one parameter by dividing through it. Then you apply fu to your data, square and add the results. This is now the error that you must minimize.

Assuming we have the following data:

Clear[a, b,x,y]
data = Table[{i, i + RandomReal[{-1, 1}/2]} , {i, 10}]

With your simple example

a + b x + c y ==0:

we e.g. divide by c and get (a and b have now different meanings):

fu[x_,y_] := a + b x + y

and get the overall error:

err = Total[fu /@ data]

To get a and b we minimize this error by:

NMinimize[err, {a, b}]

For convenience, here is everything together:

Clear[a, b,x,y]
data = Table[{i, i + RandomReal[{-1, 1}/2]} , {i, 10}]
fu[{x_, y_}] := (a + b x +  y)^2;
err = Total[fu /@ data]
res=NMinimize[err, {a, b}]

Maybe you can now solve the implicit equation for y. As you have an implicit function there may be several solutions and you have to pick one. Here we take the first one:

eq = fu[{x, y}] == 0 /. res[[2]]
fity[x_] = y /. Solve[eq, y][[1]] // Simplify
ListLinePlot[{Transpose[{data[[All, 1]], ys1}], data}]

If you can still not solve the implicit equation for y, you can at least do it numerically to get the fitted y values, using NSolve[]. Again, there may be several solutions and you may have to pick one. Here we again take the first one:

fity[{x0_, _}] := y /. (NSolve[eq /. x -> x0, y][[1]])
ys = fity /@ data;
ListLinePlot[{Transpose[{data[[All, 1]], ys}], data}]
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.