# forum.alglib.net

ALGLIB forum
 It is currently Wed Aug 17, 2022 3:28 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.

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: How to make functions depend on user input in minlmoptimizePosted: Sat Sep 08, 2012 12:14 pm

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

 Post subject: Re: How to make functions depend on user input in minlmoptimPosted: Mon Sep 10, 2012 4:34 am

Joined: Fri May 07, 2010 7:06 am
Posts: 878
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

 Post subject: Re: How to make functions depend on user input in minlmoptimPosted: Tue Sep 11, 2012 9:14 am

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 3 guests

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

Search for: