473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to solve a function?

I have a method

double myfunction(double param1){

// code here

}

The Method takes 1 parameter, and returns a double. It is continuous.

Are tehre any functions in C sharp that will help me to find param1
such that myfunction is minimised?

Sep 5 '08 #1
10 1661
On Fri, 5 Sep 2008 03:47:26 -0700 (PDT), Bernard.Mangay wrote:
I have a method

double myfunction(double param1){

// code here

}

The Method takes 1 parameter, and returns a double. It is continuous.

Are tehre any functions in C sharp that will help me to find param1
such that myfunction is minimised?
Am I the only one who didn't understand what he wants? :S

Bernard, would you please explain what do you want to accomplish?

David

--
. ''`. Debian maintainer | http://wiki.debian.org/DavidPaleino
: :' : Linuxer #334216 --|-- http://www.hanskalabs.net/
`. `'` GPG: 1392B174 ----|---- http://snipr.com/qa_page
`- 2BAB C625 4E66 E7B8 450A C3E1 E6AA 9017 1392 B174

Sep 5 '08 #2
On Sep 5, 11:47*am, "Bernard.Mangay" <fcm...@googlemail.comwrote:
I have a method

double myfunction(double param1){

// code here

}

The Method takes 1 parameter, and returns a double. *It is continuous.

Are tehre any functions in C sharp that will help me to find param1
such that myfunction is minimised?
Certainly not in C# as a language, but there's a new MS library which
might help you:
http://code.msdn.microsoft.com/solverfoundationfs1

I assume you're only looking for a local minimum? It's pretty easy to
come up with a continuous function which would be hard to find the
minimum for programmatically in any sane length of time.

Jon
Sep 5 '08 #3
On Sep 5, 11:49*am, David Paleino <dDOTpale...@gmail.c-o-mwrote:
Am I the only one who didn't understand what he wants? :S
Possibly not, but I'm pretty sure I understand it.
Bernard, would you please explain what do you want to accomplish?
Consider a function such as x =x*(x-1). That has a minimum value
when x is 1/2. I believe Bernard was trying to get that source value
(1/2) given the method which would compute the target value for any
source.

Jon
Sep 5 '08 #4
"David Paleino" <dD*********@gmail.c-o-mwrote in message
news:20*********************@gmail.c-o-m...
>I have a method

double myfunction(double param1){

// code here

}

The Method takes 1 parameter, and returns a double. It is continuous.

Are tehre any functions in C sharp that will help me to find param1
such that myfunction is minimised?

Am I the only one who didn't understand what he wants? :S

Bernard, would you please explain what do you want to accomplish?
As I understand, he wants to find an extremum of a mathematical function
represented as a C# method.
Sep 5 '08 #5
"Bernard.Mangay" <fc****@googlemail.comwrote in message
news:d7**********************************@e39g2000 hsf.googlegroups.com...
>I have a method

double myfunction(double param1){

// code here

}

The Method takes 1 parameter, and returns a double. It is continuous.

Are tehre any functions in C sharp that will help me to find param1
such that myfunction is minimised?
No. C#/VS is not a computer algebra system. If you need to solve such tasks,
you should look at Maple and other similar packages.
Sep 5 '08 #6
No; you would have to do the maths yourself. There are various
frameworks that add code for this.

There used to be a math pack on Lutz Roeder's site, but it seems to
have disappeared now that Reflector has gone to Red Gate... it might
have been a good fit, though!

Marc
Sep 5 '08 #7
JS: http://code.msdn.microsoft.com/solverfoundationfs1

A new one to me, cheers ;-p

Marc
Sep 5 '08 #8
Bernard.Mangay wrote:
I have a method

double myfunction(double param1){

// code here

}

The Method takes 1 parameter, and returns a double. It is
continuous.

Are tehre any functions in C sharp that will help me to find param1
such that myfunction is minimised?
There wouldn't be anything in the language itself and I don't think
there's anything in the .NET framework. The solver foundation that
others have mentioned may have something--I haven't had a chance to
look at it.

Beyond that, there are other options.

If you can put up with the terms of license, "Numerical Recipes in
C++", available from Amazon.com, has code samples for this sort of
thing that should run in C# with minimal modification.

Any decent text on numerical analysis should have several algorithms
for this sort of thing--I don't have a recommendation as the ones I
have are out of print.

If you just need to solve the thing and can't do it analyticall or
graphically, Wolfram puts out a product for 165 bucks called
"Mathematical Explorer" that runs on top of an older version of
Mathematica and exposes the engine--while it's not cutting edge it
shouldn't have any problem finding extrema of a continuous function.

--
--
--John
to email, dial "usenet" and validate
(was jclarke at eye bee em dot net)
Sep 5 '08 #9
Is this a homework assignment?
Sep 5 '08 #10
Bernard.Mangay wrote:
I have a method

double myfunction(double param1){

// code here

}

The Method takes 1 parameter, and returns a double. It is continuous.

Are tehre any functions in C sharp that will help me to find param1
such that myfunction is minimised?
Not any specific feature in C# or .NET, but the delegate
feature makes it easy to implement Newtons method. See
below for some code to get you started.

Arne

=================================================

using System;

namespace E
{
public class Program
{
public static double f1(double x)
{
return x*x - 2*x + 3;
}
public static double f2(double x)
{
return 1/x + x;
}
private const double START = 10;
private const double SMALL = 0.0000001;
private static double D1(func f, double x)
{
return (f(x+SMALL/2) - f(x-SMALL/2)) / SMALL;
}
public delegate double func(double x);
public static double FindLocalExtrema(func f)
{
double x = START;
double oldx;
do
{
oldx = x;
x = x - D1(f,x) / f(x);
}
while (Math.Abs(x - oldx) SMALL);
return x;
}
public static void Main(string[] args)
{
Console.WriteLine(FindLocalExtrema(f1));
Console.WriteLine(FindLocalExtrema(f2));
Console.ReadKey();
}
}
}
Sep 6 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: MAgnus | last post by:
I need something an algorithm or something else to help me with this function when a and b are given from functions before. (1-(1/(1+r))^b)/r=a this is the function is there anything that can help...
7
by: Shapper | last post by:
Hello, I have an ASP:ImageButton where I want to call a function and pass a string: OnClick="Change_Photo("John")" I am having problems with "". I tried
8
by: MyAlias | last post by:
Can't solve this CallBack returning structures Error message: An unhandled exception of type 'System.NullReferenceException' occurred in MyTest.exe Additional information: Object reference not...
0
by: Mamatha | last post by:
Hi I have one VB.NET application and i declare a thread as a public variable in the form.I want to declare this same thread as a public variable according to my flexibility,so i have to declare...
7
by: Nobody | last post by:
Anyone have a clean way of solving this define issue? In Windows, there are sometimes unicode functions and multibyte functions... the naming convention used is FunctionA for multibyte and...
1
by: ABC | last post by:
Is there any function to solve the string to values? for example: The string is "data source=DEVSRV;Initial Catalog=MyDATABASE;User ID=sa;Password=;". I expected the function can return the...
9
by: fcvcnet | last post by:
Hi, I write a class class CSegment { public: CSegment(void); public: ~CSegment(void); public: CArray< CList< CPoint, CPoint& >, CList< CPoint, CPoint& >& m_curve;
2
by: Rajoo | last post by:
Write a program which overloads a binary Minus (-) operator, The program will contain a class Matrix, This class will contain a private data member Array which store int values. The class will...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
2
by: davidson1 | last post by:
Hai friends..for menu to use in my website..i found in one website....pl look below website.... http://www.dynamicdrive.com/dynamicindex1/omnislide/index.htm i downloaded 2 files.... ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.