2
$\begingroup$

I am new to Mathematica so please bear with me. I have an equation that has around 7 parameters and one unknown. I was able to use FindRoot to solve it; however, I want to do the same for around 1000 rows of parameters. I usually do this in Excel were I just drag down the same command for all rows to get the result for each row. I tried to use the Table, Matrix, and other commands but couldn't understand how it works. I think there is something wrong with my understanding on how Mathematica works. Any suggestions on guiding me is greatly appreciated.

Edit#1

For example,

a b c f(x)=ax^2+bx+c Findroot f(x)

2 3 3 f(x)=2x^2+3x+3 ?

2 2 1 f(x)=2x^2+2x+1 ?

5 3 5 f(x)=5x^2+3x+5 ?

. . . . .

. . . . .

. . . . .

2 8 3 f(x)=2x^2+8x+3 ?

Edit#2

I tried the following as suggested by @belisarius ;however, i get " FindRoot::nveq: The number of equations does not match the number of variables in "

params = {{{61.07213, 118.844, 127.4626, 133.3232, 140.4969, 154.6745, 0.0725203, 0.0459785, 0.0538076, 0.1009101, 0.1382398, -0.0140873}, {349.7488, 115.493, 114.1906, 112.2911, 110.223, 108.051, 0.1205766, 0.1778708, 0.1969301, 0.2107067, 0.2875397, -0.0140873}, {579.7379, 332.051, 383.5087, 437.5052, 493.8236, 556.8684, 0.2324231, 0.2111662, 0.1930639, 0.1914745, 0.2012774, -0.0140873}}};

f[{m_, b0_, b1_, b2_, b3_, b4_, roe1_, roe2_, roe3_, roe4_, roe5_, gCT_}] := FindRoot[b0 + (b0 (-R + roe1))/(1 + R) + ( b1 (-R + roe2))/(1 + R)^2 + (b2 (-R + roe3))/(1 + R)^3 + ( b3 (-R + roe4))/(1 + R)^4 + ( b4 (-R + roe5))/(1 + R)^5 + ((1 + gCT) b4 (-R + roe5))/((1 + R)^5 (-gCT + R)) - m, {R, 0}]

f /@ params

Any ideas on why I get this result?

$\endgroup$
  • 2
    $\begingroup$ "...bare with me."? Do I really need to get naked? ;-} And what you're after will be in the Map and Apply families. See the docs. for more info. $\endgroup$ – ciao Jul 15 '15 at 4:31
  • $\begingroup$ It might not seem like it, but for a new user you may have picked a problem that is a little too difficult. Imagine being new to Excel. How much would you have needed to learn to do this problem? Now study this example: params = {{a, b, c}, {2, 3, 3}, {2, 2, 1}}; f[{p1_, p2_, p3_}] := x /. Solve[p1*x^2 + p2*x + p3 == 0, x]; Map[f, params] Look up each of those functions in the help system and read until you understand it. There is a lot to learn to be able to do something like this. $\endgroup$ – Bill Jul 15 '15 at 5:30
  • 2
    $\begingroup$ @Bill Impressive, isn't it? That's why many people abandon Mma: the learning curve $\endgroup$ – Dr. belisarius Jul 15 '15 at 5:34
  • $\begingroup$ @Bill Thank you very much, that really help me. $\endgroup$ – Derpsh Jul 15 '15 at 5:58
  • $\begingroup$ In your edited example you have triple curly braces in param. You should have only two levels $\endgroup$ – Dr. belisarius Jul 15 '15 at 7:14
4
$\begingroup$
(*First we defime our "rows"*)
params = {{2, 3, 3}, {2, 2, 1}, {5, 3, 5}};

(*Now we define a function of the params that solves the equation*)
f[{a_, b_, c_}] := Solve[a x^2 + b x + c == 0, x]

(*and we apply the function to each parameter set at a time*)
f /@ params // Column
(*
{{{x -> 1/4 (-3 - I Sqrt[15])}, {x -> 1/4 (-3 + I Sqrt[15])}},
 {{x -> -(1/2) - I/2}, {x -> -(1/2) + I/2}},
 {{x -> 1/10 (-3 - I Sqrt[91])}, {x -> 1/10 (-3 + I Sqrt[91])}}}
*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.