forum.alglib.net

ALGLIB forum
It is currently Thu Apr 18, 2024 10:07 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How to make functions depend on user input in minlmoptimize
PostPosted: Sat Sep 08, 2012 12:14 pm 
Offline

Joined: Sat Sep 08, 2012 11:41 am
Posts: 2
Hi.

I can't figure out if it's somehow possible to input/customize the functions to be minimized/optimized at runtime in C#.
Im making an application for economic students with a GUI. A basic thing in economics is the supply and demand curves. The students will for example see two curves and their intersection in a cordinate system. I use lmoptimize to calculate the intersection cordinates.

If the students want to change the demand or supply they can do it on the fly by moving a slider. If the demand curve is 1/x + 15 the student can change the demand by moving the curve upwards or downwards. If the user moves the demand curve upwards for example to 1/x + 17 I need to be able to recalculate the intersection between the supply and demand curve because it has changed. How can I do this on the fly?

In the example from the reference manual (example_minlm_d_v)

http://www.alglib.net/translator/man/ma ... _minlm_d_v

the function structure has to be "there" at compile time. In my program where minlmoptimize is used for calculating intersection it looks like this:


Code:
      public static void function1_fvec(double[] x, double[] fi, object obj)
        {


            fii[0] = (1 / x[0] + 15) - (x[1] - 16);
            fii[1] = (x[1] - 16) - (1 / x[0]+15);

        }


I would like to be able to change the fi function vector so the new intersection depending on the user input is calculated in real time. So the new functions in from above in this case would look like:

Code:
public static void function1_fvec(double[] x, double[] fi, object obj)
        {


            fii[0] = (1 / x[0] + 17) - (x[1] - 16);
            fii[1] = (x[1] - 16) - (1 / x[0]+17);

        }



It would be very nice if you could pass a string (or something) to and call the function1_fvec with the new user function each time he or she changed the slider. Is this possible to do or should I try to use the codedom compiler in C# which I don't have any experience in.

Thank you very much.

Greets

Hans


Top
 Profile  
 
 Post subject: Re: How to make functions depend on user input in minlmoptim
PostPosted: Mon Sep 10, 2012 4:34 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 906
There is an additional parameter obj which is passed to user-defined delegate. You can pass additional information by means of this parameter. For example, it may contain reference to structure which stores parameters of user-defined curve.


Top
 Profile  
 
 Post subject: Re: How to make functions depend on user input in minlmoptim
PostPosted: Tue Sep 11, 2012 9:14 am 
Offline

Joined: Sat Sep 08, 2012 11:41 am
Posts: 2
Sergey.Bochkanov wrote:
There is an additional parameter obj which is passed to user-defined delegate. You can pass additional information by means of this parameter. For example, it may contain reference to structure which stores parameters of user-defined curve.

Thanks a lot Sergey.

Ill try to figure it out. Im reading another post in forum I found after you told me about that.

viewtopic.php?f=2&t=386&hilit=passing+object


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 27 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group