Groups | Search | Server Info | Login | Register


Groups > comp.soft-sys.math.mathematica > #16940

Re: Numerical solution from Module

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!xmission!news.alt.net!news-out.readnews.com!news-xxxfer.readnews.com!newspump.sol.net!post2.nntp.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From Sseziwa Mukasa <mukasa@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Numerical solution from Module
Date Mon, 12 May 2014 04:45:43 +0000 (UTC)
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <lkpjln$lmb$1@smc.vnet.net> (permalink)
References <20140509060707.C211C6AE5@smc.vnet.net>
Lines 63
Organization Time-Warner Telecom
NNTP-Posting-Date 12 May 2014 04:52:04 GMT
NNTP-Posting-Host 333b8451.news.twtelecom.net
X-Trace DXC=HMcgJE=>0R>8mB8O8Rk7=0C_A=>8kQj6=;[h;PUXBgb4`9@n`L<iRV<EFiONJ7[Go6074Fh]j=j<7
X-Complaints-To abuse@twtelecom.net
Xref csiph.com comp.soft-sys.math.mathematica:16940

Show key headers only | View raw


The arguments of soln are not the a, b, and c in f.  A couple of solutions:

soln[aval_, bval_, cval_] := Module[{}, xsoln = Solve[f[x] == 0 , x]; x /.
xsoln/.{a->aval,b->bval,c->cval}]

f[x_,a_,b_,c_]:= a*x^2 + b*x + c

soln[a_,b_,c_]:=x/.Solve[f[x,a,b,c]==0,x]

On May 9, 2014, at 2:07 AM, Rob Y. H. Chai <yhchai@ucdavis.edu> wrote:

>
> Hello every one,
>
>
>
> Here is a simple question. Say I define a function
>
>
>
> In[14]:= f[x_] := a*x^2 + b*x + c
>
>
>
> Then I use Module to frame the solution of f[x] ==0
>
>
>
> In[15]:= soln[a_, b_, c_] := Module[{}, xsoln = Solve[f[x] == 0 , x]; x /.
> xsoln]
>
>
>
> When I enter numerical values for parameters a, b, and c in the module, f[x]
> never sees these numerical values, and returns a symbolic solution.
>
>
>
> In[11]:= soln[1, -3, 2]
>
>
>
> Out[11]= {(-b - Sqrt[b^2 - 4 a c])/(2 a), (-b + Sqrt[b^2 - 4 a c])/(2 a)}
>
>
>
> But I want the module to return a numerical solution as:
>
> {{x -> 1}, {x -> 2}}
>
>
>
> My question is: without bringing f[x] explicitly into the Module function,
> and without redefining f as f[a_,b_,c_][x] := a*x^2+b*x+c, how can I get the
> module to return a numerical solution?
>
>
>
> Thanks - Rob Chai
>
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar


Thread

Re: Numerical solution from Module Sseziwa Mukasa <mukasa@gmail.com> - 2014-05-12 04:45 +0000

csiph-web