numerical-methods

How to Solve Linear programming problem using DotNumerics?

家住魔仙堡 提交于 2019-12-03 13:54:56
I'm really interested in numerical analysis. I have been using DotNumerics Open Source Application. My linear system is the following: 1 * x + 3 * y <= 150 2 * x + 1 * y <= 100 where x >= 0, y >= 0 z = 10 * x + 15 * y I am trying to solve z (optimization...) I can use Simplex method to solve above problem as found in this link . I have also emailed the author, however he has not replied. using DotNumerics.Optimization; using DotNumerics; namespace App.SimplexCalcLinearProgramming { class Program { static void Main(string[] args) { Simplex simplex = new Simplex(); double[] initialGuess = new

What's the best way to calculate a numerical derivative in MATLAB?

本秂侑毒 提交于 2019-12-03 08:50:34
问题 (Note: This is intended to be a community Wiki.) Suppose I have a set of points xi = { x0 , x1 , x2 ,... xn } and corresponding function values fi = f(xi) = { f0 , f1 , f2 ,..., fn }, where f ( x ) is, in general, an unknown function. (In some situations, we might know f ( x ) ahead of time, but we want to do this generally, since we often don't know f ( x ) in advance.) What's a good way to approximate the derivative of f ( x ) at each point xi ? That is, how can I estimate values of dfi ==

Precision of calculations after exponent function

孤街醉人 提交于 2019-12-02 15:56:21
问题 I have a question regarding precision of calculations - it is more of a mathematical theory behind programming. I have a given float number X and the rounding of that number, which is accurate to 10^(-n) decimal place: X' . Now, I would like to know, if after calculating exponent function: y=2^(x) the difference between my number and the rounded number would stay on the same level of precision. I mean: |2^(X)-2^(X')| is at the level of 10^(-n-1) 回答1: Exponentiation magnifies relative error

Code Analyzer: INV is slow and inaccurate

为君一笑 提交于 2019-12-02 13:31:55
问题 When I try to calculate a matrix inverse using Matlab's inv() operation: A = rand(10,10); b = rand(10,1); C = inv(A); D = C*b; I get the following warning at the last row: INV is slow and inaccurate. Use A\b for INV(A)*b , and b/A for b*INV(A). I can change the code above into: A = rand(10,10); b = rand(10,1); C = inv(A); D = A\b; Now I don't get the warning, but I don't think this solution is better. Note: I need to store both the inverse of matrix A as well as inv(A)*c. Also, in my real

Secant method solving for pipe diameter

孤者浪人 提交于 2019-12-02 11:41:41
I am trying to write a program to solve for pipe diameter for a pump system I've designed. I've done this on paper and understand the mechanics of the equations. I would appreciate any guidance. EDIT: I have updated the code with some suggestions from users, still seeing quick divergence. The guesses in there are way too high. If I figure this out I will update it to working. MODULE Sec CONTAINS SUBROUTINE Secant(fx,xold,xnew,xolder) IMPLICIT NONE INTEGER,PARAMETER::DP=selected_real_kind(15) REAL(DP), PARAMETER:: gamma=62.4 REAL(DP)::z,phead,hf,L,Q,mu,rho,rough,eff,pump,nu,ppow,fric,pres,xnew

Precision of calculations after exponent function

↘锁芯ラ 提交于 2019-12-02 08:02:49
I have a question regarding precision of calculations - it is more of a mathematical theory behind programming. I have a given float number X and the rounding of that number, which is accurate to 10^(-n) decimal place: X' . Now, I would like to know, if after calculating exponent function: y=2^(x) the difference between my number and the rounded number would stay on the same level of precision. I mean: |2^(X)-2^(X')| is at the level of 10^(-n-1) Exponentiation magnifies relative error and, by extension, ulp error. Consider this illustrative example: float x = 0x1.fffffep6; printf ("x=%a %15.8e

How to use BigInteger in VS 2010

纵然是瞬间 提交于 2019-12-01 17:02:47
I have been trying to use the BigInteger type, that is supposedly new in .NET Framework 4.0. I don't seem to be able to get to it, and get an error when trying to reference it via Using System.Numerics. Any idea what I'm doing wrong? Sorry if this is a stupid question... Add a reference to the System.Numerics assembly to your project. a. In Solution Explorer, right-click the project node and click Add Reference . b. In the Add Reference dialog box, select the .NET tab. c. Select System.Numerics , and then click OK . Add a using directive importing the System.Numerics namespace: using System

How to get binary representation of floating-point number in PHP?

荒凉一梦 提交于 2019-12-01 16:32:19
Is there any way to get the binary representation of a floating point number in PHP? Something like Java's Double.doubleToRawLongBits() . Given a positive floating point number, I'd like to get the largest representable floating-point number which is less than that number. In Java, I can do it like this: double x = Double.longBitsToDouble(Double.doubleToRawLongBits(d) - 1); But I'm not seeing anything similar in PHP. This isn't a full answer, but the only way I know of to put a float into binary is with pack() Jenni Here is a solution I came up with using Peter Bailey 's suggestion. It

How to use BigInteger in VS 2010

假装没事ソ 提交于 2019-12-01 16:12:55
问题 I have been trying to use the BigInteger type, that is supposedly new in .NET Framework 4.0. I don't seem to be able to get to it, and get an error when trying to reference it via Using System.Numerics. Any idea what I'm doing wrong? Sorry if this is a stupid question... 回答1: Add a reference to the System.Numerics assembly to your project. a. In Solution Explorer, right-click the project node and click Add Reference . b. In the Add Reference dialog box, select the .NET tab. c. Select System

LU Decomposition from Numerical Recipes not working; what am I doing wrong?

江枫思渺然 提交于 2019-12-01 09:11:39
I've literally copied and pasted from the supplied source code for Numerical Recipes for C for in-place LU Matrix Decomposition, problem is its not working. I'm sure I'm doing something stupid but would appreciate anyone being able to point me in the right direction on this; I've been working on its all day and can't see what I'm doing wrong. POST-ANSWER UPDATE: The project is finished and working . Thanks to everyone for their guidance. #include <stdlib.h> #include <stdio.h> #include <math.h> #define MAT1 3 #define TINY 1e-20 int h_NR_LU_decomp(float *a, int *indx){ //Taken from Numerical