TransWikia.com

solve for variable in iterator limit

Mathematica Asked by r_al on February 11, 2021

Why can we not solve for P in the iterator limit in the problem below? How can it be solved?

f[P_] := 2*P
ttab[P_] := Table[t, {t, 1, f[P]}]
Total[ttab[55]]

(* 6105 *)

Solve[Total[ttab[P]] == 6105, P]

During evaluation of In[429]:= Table::iterb: Iterator {t,1,2 P} does not have appropriate bounds.

During evaluation of In[429]:= Table::iterb: Iterator {t,1,2 P} does not have appropriate bounds.

During evaluation of In[429]:= Solve::nsmet: This system cannot be solved with the methods available to Solve.

Solve[Total[Table[t, {t, 1, 2 P}]] == 6105, P]

One Answer

Clear["Global`*"]

f[P_] := 2*P

ttab[P_] := Range[f[P]]

Define the total as a function which only evaluates for a numeric argument.

total[P_?NumericQ] := Total[ttab[P]]

total[55]

(* 6105 *)

Also constrain the domain

Solve[{total[P] == 6105, 0 < P < 1000}, P, Integers]

(* {{P -> 55}} *)

However, as Chris K pointed out, the total can be simplified to

total2[P_] = Sum[t, {t, 1, f[P]}]

(* P (1 + 2 P) *)

Then the constraints can be relaxed

Solve[{total2[P] == 6105, P > 0}, P]

(* {{P -> 55}} *)

Answered by Bob Hanlon on February 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP