1
$\begingroup$

New to mma. I have assigned the results of using Solve to solve 5 variables to 5 indices of a new variable:

var = a /@ Range[70, 75]
time = 6
xn3 = Table[idirt[X, time] == -a[X]*itime[X, time], {X, 70, 75}];
sol3  = Solve[xn3, var];
acts[var] /. sol3[[1]]

The last line, with the data I have, yields the output:

acts[{0.0651511, 0.0660446, 0.0690098, 0.0705071, 0.0738969, 0.0748848}]

I now want to assign these values to an array at the indices [70,6],[71,6],[72,6],[73,6],[74,6],[75,6] to correspond to the X and time values but I am a loss at how to do this. This specific implementation requires non-integer values for time as well; does this need to be implemented using an indexing variable (there is an equal time spacing between all data points) or is there a more elegant solution?

$\endgroup$
  • $\begingroup$ You mean, like, SparseArray[ Thread[({#1, 6} & /@ Range[70, 75]) -> First@acts[{0.0651511, 0.0660446, 0.0690098, 0.0705071, 0.0738969, 0.0748848}]], {75, 75}]? $\endgroup$ – march Oct 3 '16 at 18:22
  • $\begingroup$ This works for generating the sparse matrix, but it seems to completely overwrite the previous entries when I iterate the values of time. Which function should be used to add values to the array once it is created without erasing previous ones (ie. if I am iterating time with a Do loop and using the SparseArray function in the loop)? $\endgroup$ – aiwass Oct 3 '16 at 18:34
  • 1
    $\begingroup$ There was a recent question about this very thing: mathematica.stackexchange.com/questions/127530/…. $\endgroup$ – march Oct 3 '16 at 18:39
  • $\begingroup$ note if the assignment is to a contiguous range of postions you can just do like: array[[70;;75,6]]=var/.sol3[[1]] $\endgroup$ – george2079 Oct 3 '16 at 20:43

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.