0
$\begingroup$

If I have the following code:

 temperature[q_] := RSolveValue[{b[n] == b[n - 1] - time, b[0] == 90}, b, n]; Table[{time, temperature[1000][Range[0, 3]]}, {time, {2, 3, 5}}] 

where the output results in the the first element of time being subtracted by all all elements of temperature[1000][Range[0, 3]]. The output is: {{2, {90, 88, 86, 84}}, {3, {90, 87, 84, 81}}, {5, {90, 85, 80, 75}}}.

How can I modify the code such as the subtraction is the first element of time being subtracted by the first element of temperature[1000][Range[0, 3]] and then the second element of time being subtracted by temperature[1000][Range[0, 3]] and so on as to give an output such: {90, 88, 85, 80}}

PS:This question is an extension of another question asked here General question about RSolveValue and general programming

$\endgroup$
  • 1
    $\begingroup$ What's the purpose of the argument q of temperature? It appears nowhere else. $\endgroup$ – user72309 Apr 29 at 11:32
  • $\begingroup$ @Jean-ClaudeArbaut for this particular example there is no purpose for q. I removed that part from the code to make it simpler and focus only on the part of time. But you are right, if I put for example ‘q*time’ then time would be multiplied by 1000 $\endgroup$ – John Apr 29 at 14:28
  • $\begingroup$ The problem here is that you are computing the solution of a recurrence relation where time is a constant, which yields a function n->90-n*time, and then you want to make time a variable. It won't work. Why rely on RSolveValue? You may use Accumulate, for instance: 90 - Prepend[Accumulate[#], 0]& $\endgroup$ – user72309 Apr 29 at 14:36
  • $\begingroup$ Hi @Jean-ClaudeArbaut, could you expand a little bit on how to use accumulate for time?. Where do I put the list of the variable time in this code?. Thanks $\endgroup$ – John Apr 29 at 15:31
  • $\begingroup$ As an argument. It's a function... Do you prefer f[time_]:=90-Prepend[Accumulate[time],0]? $\endgroup$ – user72309 Apr 29 at 15:32

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.