0
$\begingroup$

I would like to evaluate the code below and sort the two parameters {f2, M}. Say that i runs from 1 to 10

Clear[C1, f1, f2];i = 3;f1 = i;f2 := 1 + i^2;Eq1 := C1 f1 - C1 f2 ;Consts = Solve[Eq1 == i, {C1}];C1 := Evaluate[Consts[[1, 1, 2]]];M = Integrate[C1 x^2, {x, 0, 5}]
$\endgroup$
  • $\begingroup$ Your code is a little funny, with lots of redundancy. Does this do what you want? Table[Sort@{1 + f1^2, Integrate[f1/(f1 - (1 + f1^2)) x^2, {x, 0, 5}]}, {f1, 1, 10}]. $\endgroup$ – march Oct 18 '17 at 23:00
  • $\begingroup$ Thanx @march, in fact, my code is very complicated where I have a system of Eqs. that numerically solved, but here I was trying to simplify the problem.So, what I I would like to know is how I can evaluate the whole block repeatedly for i and sort the results $\endgroup$ – HD2006 Oct 18 '17 at 23:19
  • 1
    $\begingroup$ Table[ f1 = i; f2 := 1 + i^2; Eq1 := C1 f1 - C1 f2; Consts = First@Solve[Eq1 == i, {C1}]; Sort@{f2, M = Integrate[C1 x^2 /. Consts, {x, 0, 5}]} , {i, 1, 10}]. $\endgroup$ – march Oct 18 '17 at 23:22
  • $\begingroup$ Thanx @march, just one more thing, how can I keep the order of parameters inside the sort? because the output is mixed such that {f2,m} and few of them {m,f2} ?! $\endgroup$ – HD2006 Oct 19 '17 at 1:48
  • 1
    $\begingroup$ You said you wanted to sort them. Just remove the Sort@ part of the code. If that doesn’t do what you want, more details with sample input and output is necessary. $\endgroup$ – march Oct 19 '17 at 18:55

Your Answer

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

Browse other questions tagged or ask your own question.