+ Reply to Thread
Results 1 to 8 of 8

Using Solver With Another Iterative Routine

  1. #1
    Registered User
    Join Date
    07-31-2008
    Location
    Australia
    Posts
    12

    Using Solver With Another Iterative Routine

    I've written an iterative numerical integration Sub which works fine. Several arguments are passed to it (cell references).

    I now wish to incorporate Solver in the code process so that it reads the integration result, changes the values of two of the argument cells, after which the integration routine runs again, Solver changes the cells again, etc, until the integral is minimised.

    Overall:

    1. Initial values are set up as the arguments.

    2. The integration routine then iteratively calculates the integral, based on the passed arguments.

    3. Solver reads the integration result, then changes two of the argument cells.

    4. Steps 2 and 3 repeat until Solver determines the integral result found at step 2 has been minimised.

    (The final values of the changing cells (arguments) are then used for other things.)

    I am unable to define the structure of the VBA code to achieve this.

    I call the integration Sub, then call Solver, but Solver does a single pass only.

    How do I get the integration sub and Solver to be repeatedly called, until the minimum integral value is found, after which the result is passed back to a cell, and the code terminates?
    Last edited by kubota1000; 08-20-2008 at 10:08 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482
    hi kubota1000,

    Is there a way to know how many passes are required? here is a simple loop you could use, this loops 10 times
    Please Login or Register  to view this content.
    Will an error occur when minimizing is complete, and you try to run the code again?

  3. #3
    Registered User
    Join Date
    07-31-2008
    Location
    Australia
    Posts
    12
    Hi, thanks for your help and suggestion.

    The number of iterations made by the integrator is not known in advance. It is highly dependent on the integrand, and on the specified precision, both of which are changeable, and are passed as arguments.

    The integrator does not use any previously calculated values for its initial data. The sequence of X values is recalculated all over again, and the integrator simply repeats its process and exits with the same result.

    When the integrator converges, it puts its final result into a cell. I'm trying to get Solver to (then) use that cell as the Target cell, and to then change two other cells used by the integrand expression.

    It does seem that Solver has to be "put on hold" while it waits for the integrator to complete its iterative work, and to then exit its code. Only then should Solver read the target cell (the calculated integral value provided by the integrator), and make its changes to the changing cells as required.

    Then, the integrator has to be called again, to calculate the integral using the new changing cells data, while Solver rests up for a while... etc, etc, until the Solver exits.

    Any ideas appreciated.
    Last edited by kubota1000; 08-20-2008 at 10:11 AM.

  4. #4
    Registered User
    Join Date
    07-31-2008
    Location
    Australia
    Posts
    12
    Please, any further advice?

  5. #5
    Registered User
    Join Date
    10-02-2023
    Location
    Aktau
    MS-Off Ver
    365
    Posts
    7

    Re: Using Solver With Another Iterative Routine

    Have you been able to solve this problem? I have a similar issue

  6. #6
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Using Solver With Another Iterative Routine

    Can ypu give more details about your issue ? (a example file)
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  7. #7
    Registered User
    Join Date
    10-02-2023
    Location
    Aktau
    MS-Off Ver
    365
    Posts
    7

    Re: Using Solver With Another Iterative Routine

    Hello, the problem is the following:

    I have an excel worksheet that solves system of PDEs using newton-raphson method. The solution obviously depends on some variables that I input. There is a VBA macro (lets call it VBA1) that is used to solve the equations, after solving the equations the macro inputs the solution as values. Basically I can input variables, run macro VBA1 and it gives results as values.
    The VBA1 macro gives me modeled results, which depend on variables. I also have some real data from my experiments that I want to fit to the model. The problem can be solved by comparing these two data sets, defining SSE and minimizing it by varying input parameters. I guess it can be done by some optimization algorithm, but in excel we only have solver.
    Now the problem is that solver won’t accept the data from the model as it is pasted as values (I guess solver needs explicit solution with formulas), because there is no analytical solution, and as I mentioned earlier, I used newton-raphson iterative method for solution.
    I tried to write a macro that utilizes solver for optimization, it calls VBA1 and tries to minimize SSE, but nothing really happens. VBA1 inputs the solution as values, solver tries to change variables but nothing happens. I am not sure why it behaves like this.
    Is it possible to write a VBA utilizing solver so it can optimize variables and minimize SSE in this problem? If not possible to utilize solver then why?

    I do not have a spreadsheet with me right now, because it is an old problem that I couldn’t solve. Need to search for the file.
    I have my original post in this forum, by not able to give you a link because I am a new user)
    Last edited by nurlanj; 10-02-2023 at 01:07 PM.

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Using Solver With Another Iterative Routine

    Quote Originally Posted by nurlanj View Post
    Hello, the problem is the following:

    I have an excel worksheet that solves system of PDEs using newton-raphson method.....
    Is it possible to write a VBA utilizing solver so it can optimize variables and minimize SSE in this problem? If not possible to utilize solver then why?

    I do not have a spreadsheet with me right now, because it is an old problem that I couldn’t solve. Need to search for the file.
    I have my original post in this forum, by not able to give you a link because I am a new user)
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #1 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Looping and Solver
    By junejaja in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2008, 11:53 AM
  2. Solver Package and VBA Macros
    By junejaja in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2008, 09:02 PM
  3. Excel Solver giving wrong optimal solution
    By gtg430i in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2008, 02:29 PM
  4. Solver and Worksheet events
    By whuahu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2007, 09:38 AM
  5. SOLVER add-on problems
    By fl4sh in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-26-2007, 12:10 PM

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