0
$\begingroup$

I'm solving an NDSolve equation, like:

enito = 10;
sm = Range[enito];


For [a = 1, a < (enito + 1), a++, 

sm[[a]] = 
  NDSolve[{y''[x] + a*y[x] == 0, y[0] == 1, y'[0] == 1}, 
   y, {x, 0, 30}]]

And then I do:

valor = Range[enito];

For[a = 1, a < (enito + 1), a++, 

 valor[[a]] = 
With[{exp = Through[({y} /. First[sm[[a]]])[#]]}, exp &]];

Up to this point, I think everything is alright. Now, I'm interested in construct a list of functions with valor[[a]]. For example if I define:

F[x_] := x^2

I'm interested in have something like:

gr[[a]][x_] := valor[[a]]/F[x]

But I can't get anything similar. What can I use for obtain an list with the 10 elements of gr[[a]], making them a function (using F[x] for each one of them)? i.e, for have a list (each element, a different a) of functions of x?

I'd appreciate a lot all the answers. Thank you.

$\endgroup$
  • 2
    $\begingroup$ Minimalistic problems are nice. Make it clear, what is your goal. At the moment ti seems only the last line is relevant. $\endgroup$ – Johu Jun 9 '16 at 6:52
  • $\begingroup$ Okay, I'll try: I'm just searching for a way of get a list of functions. I'm interested in evaluate each a solution for the NDsolve, divided by x^2, and evaluated at a given x*. $\endgroup$ – Guillermo Martínez Somonte Jun 9 '16 at 6:55
  • $\begingroup$ This does give you a list of functions, without me understanding any of your NDSolve stuff. fList = Table[a/#^2 & /. a -> aa, {aa, Range[1.22, 1.88, 0.11]}] $\endgroup$ – Johu Jun 9 '16 at 7:04
  • $\begingroup$ And if my function F[x_] is numerical, and I cannot get an analytical expression for it? $\endgroup$ – Guillermo Martínez Somonte Jun 9 '16 at 7:09
  • $\begingroup$ If you would replace the last line with gr[a_,x_] := valor[[a]]/F[x], you would not be happy? $\endgroup$ – Johu Jun 9 '16 at 7:09
0
$\begingroup$

A simple solution is:

gr=Table[With[{x=#},valor[[i]]/F[x]]&,{i,Length@valor}]

Can this help?

$\endgroup$
  • $\begingroup$ That was another way of solving my problem, thanks. $\endgroup$ – Guillermo Martínez Somonte Jun 9 '16 at 7:17
  • 1
    $\begingroup$ But unlike mine this actually does, what is asked in the title of the question. You perhaps should accept this answer. $\endgroup$ – Johu Jun 9 '16 at 7:19

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.