Message Boards Message Boards

0
|
9213 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Using Solve[] to solve symbolic system of equations

Posted 9 years ago

I've been able to solve cubic spline functions given values of the function using the code below.

F1[t_] = k1 + k2*t + k3*t^2 + k4*t^3;
F2[t_] = k5 + k6*t + k7*t^2 + k8*t^3;
F3[t_] = k9 + k10*t + k11*t^2 + k12*t^3;
F4[t_] = k13 + k14*t + k15*t^2 + k16*t^3;
F5[t_] = k17 + k18*t + k19*t^2 + k20*t^3;

Solve[{F1[0] == 0, F1[5] == 3, F2[5] == 3, F1'[5] == F2'[5], 
  F1''[5] == F2''[5],
  F2[15] == 11, F3[15] == 11, F2'[15] == F3'[15], F2''[15] == F3''[15],
  F3[30] == 16, F4[30] == 16, F3'[30] == F4'[30], F3''[30] == F4''[30],
  F4[45] == 19, F5[45] == 19, F4'[45] == F5'[45], F4''[45] == F5''[45],
  F5[72] == 20, F1'[0] == 0, F1''[0] == 0}]

What I would like to be able to do is to solve these symbolically like:

Solve[{F1[t0] == Fi1, F1[t1] == Fi2, F2[t1] == Fi2, 
  F1'[t1] == F2'[t1], F1''[t1] == F2''[t1],
  F2[t2] == Fi3, F3[t2] == Fi3, F2'[t2] == F3'[t2], 
  F2''[t2] == F3''[t2],
  F3[t3] == Fi4, F4[t3] == Fi4, F3'[t3] == F4'[t3], 
  F3''[t3] == F4''[t3],
  F4[t4] == Fi5, F5[t4] == Fi5, F4'[t4] == F5'[t4], 
  F4''[t4] == F5''[t4],
  F5[t5] == Fi6, F1'[t0] == 0, F1''[t0] == 0}]

for just the k values i.e. I don't want it to think of the Fi's and t's as unknowns but rather as values that I can then plug in.

4 Replies

Maybe something like this?

fparams = {Fi1, Fi2, Fi3, Fi4, Fi5, Fi6};
tparams = {t0, t1, t2, t3, t4, t5};

Random example:

fmat = RandomReal[{-10, 10}, {3, 6}];
tmat = RandomReal[{-10, 10}, {3, 6}];

subsF = Map[Thread[fparams -> #] &, fmat];
subsT = Map[Thread[tparams -> #] &, tmat];

soln /. subsF[[1]] /. subsT[[1]]

(* Out[224]= {{k1 -> 9.94179828016, k10 -> 126.921208535, 
  k11 -> 14.0653575745, k12 -> 0.543238518835, k13 -> 86.9409886567, 
  k14 -> -8.1197838958, k15 -> -5.8283104079, k16 -> -0.433645163347, 
  k17 -> -34.2801747093, k18 -> 107.627824592, k19 -> -42.6687115907, 
  k2 -> 0.352538732018, k20 -> 3.47490257264, k3 -> 0.045099495612, 
  k4 -> 0.00192315937676, k5 -> 9.96105988746, k6 -> 0.418727726288, 
  k7 -> 0.120914957506, k8 -> 0.0308704908054, k9 -> 392.500018004}} *)
POSTED BY: Daniel Lichtblau

Loops in Mathematica are clumsy and hard to debug. Write and debug a function that does the job for a single vector in your matrix. Then use Map to apply it to each vector in your matrix in turn.

POSTED BY: John Doty

Specify explicitly the variables for which you wish to solve. The rest are then effectively treated as parameters.

F1[t_] = k1 + k2*t + k3*t^2 + k4*t^3;
F2[t_] = k5 + k6*t + k7*t^2 + k8*t^3;
F3[t_] = k9 + k10*t + k11*t^2 + k12*t^3;
F4[t_] = k13 + k14*t + k15*t^2 + k16*t^3;
F5[t_] = k17 + k18*t + k19*t^2 + k20*t^3;!
vars = Complement[Variables[{F1[t], F2[t], F3[t], F4[t], F5[t]}], {t}]
eqns = {F1[t0] == Fi1, F1[t1] == Fi2, F2[t1] == Fi2, 
   F1'[t1] == F2'[t1], F1''[t1] == F2''[t1], F2[t2] == Fi3, 
   F3[t2] == Fi3, F2'[t2] == F3'[t2], F2''[t2] == F3''[t2], 
   F3[t3] == Fi4, F4[t3] == Fi4, F3'[t3] == F4'[t3], 
   F3''[t3] == F4''[t3], F4[t4] == Fi5, F5[t4] == Fi5, 
   F4'[t4] == F5'[t4], F4''[t4] == F5''[t4], F5[t5] == Fi6, 
   F1'[t0] == 0, F1''[t0] == 0};
soln = Solve[eqns, vars];

The solution is complicated, unsurprisingly.

POSTED BY: Daniel Lichtblau

Thanks Daniel,

That worked exactly. I don't suppose you and the wider community could help me if I had a matrix of t0 through t5's and Fi1 through Fi6's? Basically if the fit we have done so far is for a single experiment, and we have maybe a hundred experiments of data and we want to fit the data for each run. Otherwise I would just have to plug in actual values and record the results each time. I don't know if there is a way to do this, perhaps a loop? I'm not too familiar with loops in Mathematica.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract