Re: Different answers between versions
- To: mathgroup at smc.vnet.net
- Subject: [mg42877] Re: Different answers between versions
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Fri, 1 Aug 2003 01:25:48 -0400 (EDT)
- Organization: The University of Western Australia
- References: <bg9n2a$pjh$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <bg9n2a$pjh$1 at smc.vnet.net>, nilton.volpato at ig.com.br (Nilton Volpato) wrote: > I'm getting different answers with the Solve function, like this: > > ************ > Version 5.0: > ************ > In[5]:= Solve[ { f[0.] == -h1, f[cmin] == 0., f[ 0.5 cmax ] == h2, > f[cmax] == 0., f[.94 lmax ] == h1, f[ .75 cmax ] == h2/3., f'[0.] == > 0., f'[0.5 cmax] == 0., f'[cmax] == 0., f''[cmin] == 0. } //. { > cmax->480., cmin->120., lmax->600., h1->100., h2->120., > f[x_]->Plus@@Table[ a[i] x^i, {i,0, 9}] } ] > Solve::svars: Equations may not give solutions for all "solve" > variables. Modifying your code slightly, replacing Plus@@Table with Sum, if you look at the output of { f[0.] == -h1, f[cmin] == 0., f[ 0.5 cmax ] == h2, f[cmax] == 0., f[.94 lmax ] == h1, f[ .75 cmax ] == h2/3., f'[0.] == 0., f'[0.5 cmax] == 0., f'[cmax] == 0., f''[cmin] == 0. } /. {cmax->480., cmin->120., lmax->600., h1->100., h2->120., f[x_]->Sum[ a[i] x^i, {i,0, 9}] } you will see that f is _not_ being substituted into the derivative expressions. This can be fixed as follows: I've also replaced all the floating-point numbers by exact integer or rational expressions (which helps take into account ill-condition problems -- you can use Rationalize to automate this). fpoly[x_] = Sum[a[i] x^i, {i, 0, 9}]; Solve[{f[0] == -h1, f[cmin] == 0, f[cmax/2] == h2, f[cmax] == 0, f[47/50 lmax] == h1, f[3/4 cmax] == h2/3, f'[0] == 0, f'[cmax/2] == 0, f'[cmax] == 0, f''[cmin] == 0} /. {cmax -> 480, cmin -> 120, lmax -> 600, h1 -> 100, h2 -> 120, f -> Function[x, Evaluate[fpoly[x]]]}]; fpoly[x_] = fpoly[x] /. First[%] There is, perhaps, a better way to proceed: Since you are doing polynomial interpolation, why not use the built-in Interpolation? Here is your problem re-cast as 5th order Interpolation (note the free parameter a corresponding to the unspecified first derivative at cmin): fint[a_] = Interpolation[{ {0, {-h1, 0}}, {cmin, {0, a, 0}}, {0.5 cmax, {h2, 0}}, {0.75 cmax, h2/3.}, {cmax, {0, 0}}, {0.94*lmax, h1}} /. {cmax -> 480., cmin -> 120., lmax -> 600., h1 -> 100., h2 -> 120.}, InterpolationOrder -> 5] and here is a plot of the family of interpolating curves for a in [-5,5]: Plot[Evaluate[Table[fint[a][x], {a, -5, 5}]], {x, 0, 564}, PlotRange -> All]; Cheers, Paul -- Paul Abbott Phone: +61 8 9380 2734 School of Physics, M013 Fax: +61 8 9380 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul at physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul