Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:02:46+00:00 2026-05-23T17:02:46+00:00

I have the following Nested table (myinputmatrix = Table[Nest[function, myinputmatrix[[i]][[j]], myinputmatrix[[i]][[j]][[2]][[2]] + myinputmatrix[[i]][[j]][[3]][[2]]], {i,

  • 0

I have the following Nested table

 (myinputmatrix = Table[Nest[function, myinputmatrix[[i]][[j]], 
 myinputmatrix[[i]][[j]][[2]][[2]] + 
  myinputmatrix[[i]][[j]][[3]][[2]]], {i, 
 Dimensions[myinputmatrix][[1]]}, {j, 
 Dimensions[myinputmatrix][[2]]}]) // TableForm

fq[k_?NumericQ] := Count[RandomReal[{0, 1}, k], x_ /; x < .1]

 function[x_List] :=  ReplacePart[
 x, {{2, 1} -> x[[2]][[1]] - #1, 

{2, 2} -> x[[2]][[2]] + #1,

{3, 1} -> x[[3]][[1]] - #2, {3, 2} -> 
   x[[3]][[2]] + #2}] &[fq[x[[2]][[1]]], fq[x[[2]][[1]]]];

My problem is that I want to add only the #1 in the bold part above, but not only the new one, I want it to add all #1 for the n times (Nest function times]

If I try the function

 function[x_List] :=  ReplacePart[
 x, {{2, 1} -> x[[2]][[1]] - #1, {2, 2} ->   #1,
  {3, 1} -> x[[3]][[1]] - #2, {3, 2} ->  #2}] &[fq[x[[2]][[1]]],
 fq[x[[2]][[1]]]];

I am having as a result the last value of fq[k]. I thought of replacing that part in my table with 0 but is not going to work since I am using it in my nested list, also I thought of substricting that part from my initial table but I am not sure which way is the best to do it and if the way I am thinking is the correct one. Can anyone help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:02:47+00:00Added an answer on May 23, 2026 at 5:02 pm

    If I may restate the problem and hopefully clarify the question for myself. At each iteration in the Nest, you want to add not the current (random) output from fq, but the cumulation of the current and all past values of it. But because the random output depends at each iteration on the input matrix, you need to calculate both the random number and the current value of the matrix in the same iteration.
    If that hadn’t been true you could use Fold.

    Restating fq as Sasha suggested EDIT with some type checking to avoid problems with incorrect input:

    fq[k_Integer?Positive]:=RandomVariate[BinomialDistribution[k,.1]]
    

    You might want to add some other error checking code. Something like this, depending on your requirements, might do.

    fq[0]:= 0;
    fq[k_Real?Positive]:=RandomVariate[BinomialDistribution[Round[k],.1]]
    

    You need function to take the random numbers as parameters. EDIT 1 and 2 I have changed the syntax of this function to use the parameters explicitly instead of the original question’s anonymous function within a function. This should avoid some syntax errors. Also note that I have used “NumericQ” rather than “Real” as the type for the rv1 and rv2 parameters, because they can be integers at the start of the Nest iteration.

    function[x_List, rv1_?NumericQ, rv2_?NumericQ] :=  ReplacePart[
     x, {{2, 1} -> x[[2]][[1]] - rv1, {2, 2} ->   rv1,
     {3, 1} -> x[[3]][[1]] - rv2, {3, 2} ->  rv2}]
    

    And then pass the current random number as a local constant using With to a Nest function that works on a list containing your matrix and the cumulation of the random variates. I have used myoutputmatrix because I really don’t like the idea of rewriting existing expressions all the time. That’s just me. Now, the one other thing is that you need to set n, the number of iterates. I’ve set it to 5 but you can make this a parameter in a function if you want (see below).

    (myoutputmatrix = Table[ First[Nest[With[{rv=fq[#1[[1]][[2]][[1]] ]}, 
    {function[#1[[1]],rv, rv+#1[[2]] ],rv+#1[[2]] }]&, 
     { myinputmatrix[[i]][[j]], 0 }, 5]],
     {i,  Dimensions[myinputmatrix][[1]]}, {j, 
     Dimensions[myinputmatrix][[2]]}]) // TableForm
    

    The First is there because in the end you only want the matrix, not the cumulation of the random variates.

    outputmatrix[input_List, n_Integer?Positive] /; 
      Length[Dimensions[input]] == 4 := 
      Table[First[
       Nest[With[{rv = fq[#1[[1]][[2]][[1]]]}, {function[#1[[1]], rv, 
        rv + #1[[2]]], rv + #1[[2]]}] &, {input[[i]][[j]], 0}, n]],
        {i, Dimensions[input][[1]]}, {j, Dimensions[input][[2]]}]
    
    outputmatrix[myinputmatrix, 10] // TableForm
    

    EDIT I have checked this now and it runs, but note that you can get negative numbers in the output, which is not what you want, I don’t think.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table with a nested table in it: <table class=datagrid id=report>
I am using a table nested in a table which happens to have the
I'm often confronted with the following situation: I have some data in a table
I have the following html structure (which is generated and I can't change): <table
I have the following markup as a part of a Razor view: <table> <caption>Presidents</caption>
I have a question taken from pg 16 of IBM's Nested Relational Database White
I have a the following rails models: class Release < ActiveRecord::Base has_many :release_questionnaires, :dependent
I have the following design: (source: kawoolutions.com ) Simple logic: Foos uses a multi-column
I have the following code in my models: Class Farm < ActiveRecord::Base has_many :farm_products,
I have a table that logs various transactions for a CMS. It logs the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.