0
$\begingroup$

For a project I have, I have let a program calculate required interias and friction for my system are R and J in the params. That program calculated 0.5*10^-3 and 0.013~ respectively. I'm trying now to find these empirically.

Update nr 2

This model is a dampened motor described via the ode, i have several data sets, where I know all of the initial conditions and boundary conditions:

  1. u-> amps
  2. tau-> torque Nm/a
  3. C1-> angular velocity
  4. C2-> angular accel.
  5. t how much time each system takes to come to a stop, in the given data set: 17 seconds.

R is friction and J is system inertia, are the values I'm attempting to fit, the rest are known, R I expect as friction to be considerably small and near 0.05*10-5, while J also small, should be between 0.001 and 0.002.

params = {u -> 0, \[Tau] -> 33.5 10^-3, J -> (339.10 10^-6 + 130 10^-6 + 0.09^2 0.1102), R -> 0.05 10^-3, C[2] -> 0, C[1] -> 177.37};

D[DSolve[{J \[Phi]''[t] == \[Tau] u - R \[Phi]'[t]}, \[Phi][t], t], t]

System params and the ode required to for fitting,

funk[t_] := (u \[Tau])/R + E^(-((R t)/J)) C[1]

When Plotting the function gives me a plot that seems quite reasonable,

Plot[funk[t] /. params // Evaluate, {t, 0, 17}, ImageSize -> Medium,PlotRange -> All]

plot1

I have some experimental data, to match it with,

ListPlot[data, ImageSize -> Medium, DataRange -> {0, 17},PlotRange -> All]

plot2

Trying to use show and overlay them to compare gives me:

Show[listplot, Plot[{funk[t] /. params} // Evaluate, {t, 0, 17}]]

plot3

So i thought it was a legends problem...or something else. Until I started playing around with time in the inital plot, which ends up changing the entire function plot.

Plot[funk[t] /. params // Evaluate, {t, 0, 25}, ImageSize -> Medium,PlotRange -> All]

plot4

Now I realize that the e function will never be equal to zero...and that mathematica when approaching limits does weird things when it comes to plotting (atleast, what I've come to learn from using OutPutResponse[] and etc)

But I don't expect this function to change so drastically...Or be completely different when using Show[]

So What gives? Is this some kind of bug? Why do I get different plots when using different ranges of time, and why Doesn't Show[] overlay the two plots correctly? I have used this successfully before in other projects.

I'd greatly appreciate the help, I must be doing something stupidly wrong, but it's driving me crazy.

Thanks again!

Here is half of the data to keep things small:

data = {{17/60, 177.39}, {17/30, 173.62}, {17/20, 169.41}, {17/15,165.88}, {17/12, 162.19}, {17/10, 158.47}, {119/60, 155.07}, {34/15,151.48}, {51/20, 147.93}, {17/6, 144.32}, {187/60, 140.92}, {17/5,137.29}, {221/60, 133.94}, {119/30, 130.67}, {17/4, 127.4}, {68/15,123.82}, {289/60, 120.6}, {51/10, 116.91}, {323/60, 113.54}, {17/3,110.09}, {119/20, 106.86}, {187/30, 103.5}, {391/60, 100.06}, {34/5,96.88}, {85/12, 93.62}, {221/30, 90.47}, {153/20, 87.51}, {119/15,84.68}, {493/60, 81.33}, {17/2, 78.31}, {527/60, 75.49}, {136/15,72.44}, {187/20, 69.44}, {289/30, 66.38}, {119/12, 63.3}, {51/5,60.86}, {629/60, 58.19}, {323/30, 55.52}, {221/20, 52.51}, {34/3,49.8}, {697/60, 47.17}, {119/10, 44.43}, {731/60, 41.85}, {187/15,39.05}, {51/4, 36.4}, {391/30, 33.91}, {799/60, 31.08}, {68/5,28.63}, {833/60, 26.15}, {85/6, 23.65}, {289/20, 21.23}, {221/15,18.62}, {901/60, 16.41}, {153/10, 13.93}, {187/12, 11.62}, {238/15,9.44}, {323/20, 7.34}, {493/30, 5.24}, {1003/60, 4.04}, {17, 3.67}}

Data set updated to comments suggestions, and plotting via Epilog, unfortunately still fails...

 Plot[{funk[t] /. params}, {t, 0, 17}, Epilog -> Point[fitdata]]

plot5

$\endgroup$
  • $\begingroup$ I am not certain this is your problem, but is there any chance you could get that data in the form {{t1,y1},{t2,y2},...}? Without that t1,t2,.. ListPlot assumes {y1,y2,...} are measured at 1,2,3,.. and this can cause scaling problems when overlaying plots. $\endgroup$ – Bill Nov 23 '18 at 19:37
  • $\begingroup$ Oh yes, that's a good point, I updated the dataset. Unfortunately, it didn't change the plotting weirdness though :( $\endgroup$ – morbo Nov 23 '18 at 23:02
1
$\begingroup$

This is just a follow-up on @BobHanlon 's answer.

The model funk is way over parameterized. First of all, $u$ and $\tau$ always appear together as the product $u\tau$. That means that at best only the product of those two parameters can be estimated.

Also, given the structure of the model one can see that it can be reduced to the form

$$a+c e^{-b t}$$

as there are only 3 (and not 5) parameters that one can estimate.

funk[t_] = a + c Exp[-b t];
nlm = NonlinearModelFit[data, funk[t], {a, b, c}, t]
nlm["BestFitParameters"]
(*  {a -> -251.4377380226784,b -> 0.03094657049466166,c -> 433.176013328645} *)
Show[ListPlot[data],
 Plot[nlm[t], {t, Min[data], Max[data]}]]

Function and fit

$\endgroup$
  • $\begingroup$ I updated the post to be more specific, because I see I wasn't accurate enough, so I apologize. However you're right, if I let the system estimate a, c and b, oddly the data and the curve match. However, I am actually only trying to estimate -b, which is actually a ratio of -R/J in my original question, I have all other data. $\endgroup$ – morbo Nov 24 '18 at 10:04
  • $\begingroup$ It's not odd that the data and the curve match. $\endgroup$ – JimB Nov 24 '18 at 17:30
  • $\begingroup$ Yes you’re right, poor choice of words. It’s odd mine doesn’t match. $\endgroup$ – morbo Nov 24 '18 at 18:59
0
$\begingroup$

It is not clear where your values for params come from. Using your data and fitting to your model

funk[t_] = (u τ)/R + E^(-((R t)/J)) c;

nlm = NonlinearModelFit[data, funk[t], {J, R, u, τ, c}, t] // Quiet;

params = nlm["BestFitParameters"]

(* {J -> 1157.21, R -> 38.6683, u -> -75.4681, τ -> 121.24, c -> 418.571} *)

Comparing the fitted model with the data

Plot[nlm[t], {t, 0, 17},
 PlotStyle -> Thick,
 ImageSize -> Medium,
 PlotRange -> All,
 Epilog -> {Red, AbsolutePointSize[4], Point[data]}]

enter image description here

$\endgroup$
  • $\begingroup$ Ah yes, I apologize and have explained (hopefully better this time, ahah!) and updated the question. R and J are the values I'm looking for, if I use your example, like the other answer, they do align correctly. However, when only fitting for R and J, I still cannot get the plots to align. $\endgroup$ – morbo Nov 24 '18 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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