| Author |
Comment/Response |
Dr. Frank Solina Gilbert
|
09/28/05 6:01pm
Hi @all :),
First of all. I am a newbie in using mathematica. Please be patient.
I have developed a mathematical model in form of an differential equation for my task.
Now, I want to fit my data consisting of a set of 500 points (x1,x2,y). So I wrote the following code.
\!\(HSE[A_?NumberQ, B_?NumberQ, C_?NumberQ, D_?NumberQ] := Block[{sol,
f}, sol = \(NDSolve[{\((A + B\ Abs[f[t]] + C\
f[t]\^2 + D\ Abs[f[t]\^3])\)\ f[
t] + C\ \(f'\)[
t] == \ 0\ , f[0] == 0},
f, {t, 0,
500}, Method ->
"\<Automatic\>"]\)[\([1]\)]; Plus @@ \
Apply[\((f[#1] - #2)\)^2 &, data, {
1}] /. sol]; \ NMinimize[HSE[A, B, C, D], {A,
B, C, D}, \ Method -> "\<NelderMead\>"]\)
Solving this problem with a data set of 2 colums is not a problem, but I get an error message, if I use a data set with 3 colums like the following one:
ata = {{1.0,
0.014, 0.01}, {2.0, 1.4, 1.5}, {1.005,
2.1104, 4.44}, {8.0, 3.0, 0.144}, {.1, -.1, 0.114}};
I want to use the thirth colum as my vibration initiator. Then the code above becomes like this:
\!\(HSE[A_?NumberQ, B_?NumberQ, C_?NumberQ, D_?NumberQ] := Block[{sol,
f}, sol = \(NDSolve[{\((A + B\ Abs[f[t]] + C\
f[t]\^2 + D\ Abs[f[t]\^3])\)\ f[
t] + C\ \(f'\)[t] == \ g[t]\ , f[
0] == 0}, f, {t,
0, 500}, Method -> "\<Automatic\>"]\)[\([1]\)]; Plus \
@@ Apply[\((f[#1] - #2)\)^2 &, data, {1}] /. sol]; \
NMinimize[HSE[A, B, C, D], {A, B, C,
D}, \ Method -> "\<NelderMead\>"]\)
Mathematica says that the number of equations do no not match the number of parameters. I don't know waht to say, I am using Mathematica only since one week.
I would really appreatiate it, if someone could tell that I used a wrong syntax in my code.
Thnaks in advance, for your help.
Franc Solina Gilbert
URL: , |
|