+ Reply to Thread
Results 1 to 3 of 3

Problem Displaying Specific Data From a Simple Model

Hybrid View

ask4thesea Problem Displaying Specific... 04-01-2011, 08:43 PM
abousetta Re: Problem Displaying... 04-01-2011, 10:01 PM
ask4thesea Re: Problem Displaying... 04-01-2011, 10:48 PM
  1. #1
    Registered User
    Join Date
    04-01-2011
    Location
    brighton
    MS-Off Ver
    Excel 2007
    Posts
    4

    Question Problem Displaying Specific Data From a Simple Model

    Hi, this may well be something basic that I'm missing, but I seem to be hitting my head against a brick wall. Any help would be gratefully appreciated!

    I'm trying to run a basic model, the time step for the model is small (0.01), so I only want to display the data at a few key time points. The code seems to do this okay for small numbers (the initial time point is 1 and if I ask it to report m at t = 1.02 and t = 1.03 it will display the correct result in the requested cells) but not for anything much higher (I need it to report m at t = 1, 2, 3 ect up to 10, but if I ask it to report m at t = 2 and t = 3 nothing appears on the spreadsheet).

    Private Sub CommandButton1_Click()
    k = Cells(3, 2)
    y = Cells(4, 2)
    dt = Cells(6, 2)
    
    im = Cells(9, 2) 'im is initial mass
    it = Cells(10, 2) 'it is initial time
    
    m = im
    t = it
    
    Do While t < 10
    
    dmdt = k * Exp(-y * t) * m
    dm = dmdt * dt
    m = m + dm
    t = t + dt
    
        If t = 2 Then
        mii = m
        End If
    
    Cells(13, 2) = mii
    
    If t = 3 Then
        miii = m
        End If
    
    Cells(14, 2) = miii
        
    Loop
    End Sub

    If you need any more information, please let me know. Thanks in advance, Jo
    Attached Files Attached Files
    Last edited by ask4thesea; 04-01-2011 at 11:15 PM. Reason: Edited to attach file

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Problem Displaying Specific Data From a Simple Model

    Hi Jo,

    Why does t have to be less than 10?

    Do While t < 10
    I changed it to 100 and it chugging away. I am being too naive? but I have also been up since 3 AM and the effects of the coffee is starting to wear off.

    abousetta

  3. #3
    Registered User
    Join Date
    04-01-2011
    Location
    brighton
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Problem Displaying Specific Data From a Simple Model

    Hi abousetta, it's 3.30am for me so I'm probably not much better!

    I'm pretty new to this, so I might be completely wrong, but I set it to less than 10 as I only need to see the results up until the time (t) equals 10? Either way, that part of the model seems to run okay, it's getting the results I need onto the spread sheet that's the problem.

    What I would like to happen is that when t hits 2, for the mass (m), at that point, to be reported on the spread sheet, then when t hits 3, the result for m at that point to be reported in the cell below.

    Like I said above, it works if I ask it to report m when t = 1.02 (or 1.03 etc up to 1.1), but when I increase t above 1.1 it runs, but doesn't put anything in the cell.

    Try changing

    If t = 2 Then
        mii = m
        End If
    for

    If t = 1.02 Then
        mii = m
        End If
    and you might see what I mean better.

    I need to graph the data with results from other models. Different models have to be run at different time steps, so to save confusion I just want to see the results for m at the time steps 1, 2, 3 etc., not all the smaller time steps between.
    Last edited by ask4thesea; 04-01-2011 at 11:21 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1