f

#### Numerical solution from Module

```Hello every one,

Here is a simple question. Say I define a function

In:= f[x_] := a*x^2 + b*x + c

Then I use Module to frame the solution of f[x] ==0

In:= 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:= soln[1, -3, 2]

Out= {(-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

``` 0  Rob
5/9/2014 6:07:46 AM comp.soft-sys.math.mathematica  28821 articles. 0 followers. 1 Replies 1073 Views Similar Articles

[PageSpeed] 28

```I would put f inside the module as well. Here is my version:

Clear[soln, a, b, c]
soln[a_, b_, c_] := Module[{xsoln, f, x},
f[x_] = a*x^2 + b*x + c;
xsoln = Solve[f[x] == 0, x]; x /. xsoln
]

Try it out:

soln[1,2,3]

output: {-1-I Sqrt,-1+I Sqrt}

On 5/9/2014 2:07 AM, Rob Y. H. Chai wrote:
> Hello every one,
>
>
>
> Here is a simple question. Say I define a function
>
>
>
> In:= f[x_] := a*x^2 + b*x + c
>
>
>
> Then I use Module to frame the solution of f[x] ==0
>
>
>
> In:= 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:= soln[1, -3, 2]
>
>
>
> Out= {(-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
>
>

``` 0  Kevin
5/12/2014 4:44:02 AM Similar Artilces:

modules, modules, modules
Is it just me or do most Perl modules (Cpan) exist outside of perl standard distribution? The phrase "try this module" casually uttered here. Am I mistaken, so many beta this and beta that listings. If I put out a module on CPAN is it a guarantee of fittness for any user of it? There is so much crap and garbage out there on CPAN it makes my head spin (Telnet being one). I've given up on anything but in the official distribution. Can anyone tell me why I've done that, or am I just imagining things? robic0 <> wrote: > Is it just me or do most Perl modules (Cpan) ex...

Analytic Solution != Numerical Solution
Dear Group members, I ran into a case where Mathematica Solve yields different solutions depending on whether I solve it analytically (and then plug in some numbers) or numerically. I'm solving an algebraic equation, with some square roots. Mathematica does NOT complain about branch cut or anything else when solving the problem analytically. Based on physical reasoning that created the equation in the 1st place the purely numerical solution is the correct one. I attached a 3-line pdf version of the notebook that demonstrates this issue. Thank you for any suggestions! https://docs.goo...

Digits, VPA, N, Matlab, Mathematica
Hello, Can someone help me with an issue about digits and vpa command? The limit of digits in matlab is only 50? For example, I've done the following test: >> digits Digits = 100 >> vpa((1+sqrt(5))/2,100) ans = 1.618033988749894902525738871190696954727172851562500000000000000000000000000000000000000000000000000 (note the 0's) Now, using Mathematica i've able to get it: In:= N[(1+Sqrt)/2,100] Out= 1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137 Question 1) : How can I get the same answer in Matlab a...

imputils
Hello, I've created an archive import class (with the help of importers.py from the python /demo/imputil dir) which imports packages and modules from a dictionary. So far so good. The problem is that every import statement after the code: imputil.ImportManager().install() sys.path.insert(0, DictImporter(archive)) sys.path.insert(0, imputil.BuiltinImporter()) tries to import from the dictionary and doesn't use the modules that were imported before. For example, I would like to use os in a module that's stored in the dictionary. The import os statement tries to import os from ...

Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** IDLE 1.1.2 >&g...

No math module??
I have been trying to run a python program and I get the following error: Traceback (most recent call last): File "<string>", line 39, in ? File "/home/Larry/.blender/scripts/bzflag/__init__.py", line 22, in ? import BZfileRead File "/home/Larry/.blender/scripts/bzflag/BZfileRead.py", line 24, in ? import BZsceneWriter File "/home/Larry/.blender/scripts/bzflag/BZsceneWriter.py", line 25, in ? import BZcommon File "/home/Larry/.blender/scripts/bzflag/BZcommon.py", line 24, in ? import math ImportError: No module ...

numeric module
Hello, What's the problem with this code? I get the following error message: File "test.py", line 26, in test print tbl[wi][bi] IndexError: index must be either an int or a sequence ---code snippet---- from Numeric import * tbl = zeros((32, 16)) def test(): val = testme() wi = crc >> 4 bi = crc & 0xFL print wi print bi print tbl[wi][bi] def testme(): val = 0xFFFFFFL val >>= 23 return val if __name__ == '__main__': test() Thanks, -SB In function test(), Read wi and bi as: wi = val >> 4 b...

math =!= mathematica
Does somebody know why I get different behaviour for the following commands in a commandline session of mathematica 7 or inside a notebook? It also seems to be different in different Mathematica versions for the notebook format. See http://www.risc.jku.at/people/hemmecke/mathematica/ for the notebook files for Mathematica 5.2, 6.0, 7.0. Can someone explain the General::dupsym: The symbol Array with context A` already exists. message? Why does that message appear at all? If A`Array exists, then Mathematica should just use it, shouldn't it? According to http://reference.wol...

numerical solution
(Xp-Xt)^2+(Yp-Yt)^2+(Zp-Zt)^2=Rt^2 (Xp-Xr)^2+(Yp-Yr)^2+(Zp-Zr)^2=Rr^2 psi*(Xp-Xt)+n?*(Yp-Yt)^2+eta*(Zp-Zt)=0 Die 3 Unbekannten sind Xp,Yp,Zp Alle anderen Parameter sind bekannt. Hat jemand eine Idee wie ich diese Gleichung mit Matlab l?sen kann. Vielen Dank "m? " <maximilian.mueth@eads.com> wrote in message <g4abrc\$9pt\$1@fred.mathworks.com>... > (Xp-Xt)^2+(Yp-Yt)^2+(Zp-Zt)^2=Rt^2 > (Xp-Xr)^2+(Yp-Yr)^2+(Zp-Zr)^2=Rr^2 > psi*(Xp-Xt)+n?*(Yp-Yt)^2+eta*(Zp-Zt)=0 > > Die 3 Unbekannten sind > > Xp,Yp,Zp > > Alle anderen Parameter sind bekannt. ...

Math Modules
I am considering looking into Perl. I like C because it's for OS design and such. But what kind of math capabilities does perl have ? Especially with modules? I want to expand and factor various identities and equations. Quadratic and otherwise. Linear algebra interests me too. Bill On Sat, 17 May 2014 23:10:48 -0400, Bill Cunningham wrote: > I am considering looking into Perl. I like C because it's for OS design > and such. But what kind of math capabilities does perl have ? Especially > with modules? I want to expand and factor various identities and ...

handling exact solution from solve vs numerical solution from fsolve for same equation
hello; I am asking for the difference between > Digits:=200; > > eq:=-x^3+6*x^2-6*x-1: > fsolve(eq=0,x); > > solve(eq=0,x); > evalf(%); The result of evalf(%) above contains a complex part. No matter how large I make Digits to be. the result of fsolve contains only real part. The question is, would you consider this equation to have complex or real roots? thanks, Nasser In article <rXV3f.2604\$tV6.1659@newssvr27.news.prodigy.net>, Nasser Abbasi <nma@12000.org> wrote: |>I am asking for the difference between ...

InverseLaplaceTransform different solution in Mathematica 6 and Mathematica 7.0.0.
Dear friends, Mathematica 6 gives the analytical right answer evaluating InverseLaplaceTransform[E^((1 - Sqrt[1 + 4*d*(s + d*r)])/(2*d)), s, t], However Mathematica 7.0.0 does not the analytical solution. Is it a bug? Guillermo Hi, a result with System`LaplaceTransformDump`iPowerExpand[] in it is a bug. Regards Jens Guillermo Sanchez wrote: > Dear friends, > Mathematica 6 gives the analytical right answer evaluating > InverseLaplaceTransform[E^((1 - Sqrt[1 + 4*d*(s + d*r)])/(2*d)), s, > t], > However Mathematica 7.0.0 does not the analytical sol...

infection model of numeric coercion in Mathematica [Was: Re: Numerical accuracy/precision
----- Original Message ----- > From: "Bill Rowe" <readnews@sbcglobal.net> > [...] > >So to my opinion Mathematica does the following: 1) first convert > >all numbers to numbers of the lowest precision found in the > >expression, 2) follow the usual evaluation chain. Am I correct? > > I don't know if this is entirely true. In my experience, > Mathematica converts numbers in any expression containing both > machine precision numbers and higher precision numbers to > machine precision before completing the evaluation. But I...

FA: TI-58/59 Math/Utility Module and Marine Navigation Module, (seperatly)
Thanks for looking. http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&rd=1&item=5761010357&ssPageName=STRK:MESE:IT http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&rd=1&item=5761011466&ssPageName=STRK:MESE:IT ... Web resources about - Numerical solution from Module - comp.soft-sys.math.mathematica

Numerical - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ... Numerical Simulation of Nix's Rotation - YouTube
This is a numerical simulation of the orientation of Nix as seen from the center of the Pluto system. It has been sped up so that one orbit of ... Gillian Heinrich’s has numerical advantage at Sunday’s Gold Coast races
THERE will be a Chris Waller-like feel at the Gold Coast races on Sunday when local trainer Gillian Heinrich saddles up four of the 10 runners ... Today’s Best Apps: Numerical, The Tonight Show, Digestable And R-TYPE II
... simply tap an item for more information, such as manufacturing process and any common side effects, typically stated in layman’s terms. Numerical: ... Numerical: Calculator Without Equal
Holen Sie sich „Numerical: Calculator Without Equal“ im App Store. Sehen Sie sich Screenshots, Bewertungen und Kundenrezensionen dazu an. Download this app right now: Numerical for iPhone and iPad is now free
... deals on well-designed apps, however, we'll also bring them to your attention individually — and such is the case with Andrew J Clark's " Numerical ...

FOMC Minutes: "Most participants agreed numerical thresholds could be useful"
... response to incoming data on the economy . Many participants thought that more-effective forward guidance could be provided by specifying numerical ... Quentin Tarantino's Next Western Reportedly Has A Numerical Title
Quentin Tarantino is a filmmaker who is known for making particular kinds of films, with adrenaline and testosterone always on full display, ... Divided Fed considers numerical triggers for rates policy
AFP Divided Fed considers numerical triggers for rates policy CNBC.com WASHINGTON (Reuters) - The US Federal Reserve may adopt numerical thresholds ...

Resources last updated: 1/26/2016 11:04:10 PM