0

I have to convert a Matlab script to C#. The matlab code uses fsolve() to find the fixed point of a function.

function Pr2=adiab(Pr1,Tr1,Pv1,Tv1,Pv2,k,kv,Vv,Vr)
    Pr2=(Pr1^(1/k)-Vv/Vr*Tr1/Tv1*Pr1^((1-k)/k)*(Pv2^(1/kv)/Pv1^((1-kv)/kv)-Pv1))^k;
end
% ...
Prav(i+1)=fsolve(@(Pr2) Pr2-adiab(Prav(i),Trav(i),Pa,Ta,Pr2,k,kv,Vvt,Vrt),Prav(i));

I know I need a numerical solver but there are so many I don't know which method is best suited for this problem.

  • Math.NET has a bunch of root finding algorithms.
  • Numerical has methods to solve non-linear equations:

    Non Linear Equations Solving

    • Newton's method
    • Secant method
    • Half Division method
    • Chord method
  • I can't use alglib: the free version has a GPL license, the commercial one is too expensive.

knarf
  • 2,672
  • 3
  • 26
  • 31
  • Did you look into other questions which ask for C# solver libraries? see e.g. http://stackoverflow.com/a/1217567/678093; another possibility is to call Matlab from C#: http://de.mathworks.com/help/matlab/matlab_external/call-matlab-function-from-c-client.html – m.s. Apr 13 '15 at 12:50
  • I've used [alglib](http://www.alglib.net/) in the past and would recommend it – Dan Apr 13 '15 at 12:59
  • Numerical implements many solving methods for specific problems. I don't know which kind my problem needs. – knarf Apr 13 '15 at 12:59

0 Answers0