# Questions tagged [numerical-methods]

Algorithms which solve mathematical problems by means of numerical approximation (as opposed to symbolic computation).

161 questions
Filter by
Sorted by
Tagged with
2answers
8k views

### Newton's method to solve cubic equations

I have used the Newton-Raphson method to solve Cubic equations of the form $$ax^3+bx^2+cx+d=0$$ by first iteratively finding one solution, and then reducing the polynomial to a quadratic a1*x^2+b1*x+...
5answers
971 views

### Probabilistic matchmaking simulation

The following is a problem I found on this wiki. What can I do to optimize my algorithm, and make this code more C++11? Write a program to discover the answer to this puzzle:"Let's say men and ...
2answers
421 views

### Hamiltonian Monte Carlo in Scala

I'm writing a program in Scala to perform Hamiltonian Monte Carlo (HMC), coupled with Gibbs sampling of some variables. The algorithm, with the modifications such as perturbing epsilon and l and ...
1answer
1k views

### Integral using Simpson's Rule

As an answer to this problem: Exercise 1.29 Simpson's Rule is a more accurate method of numerical integration than the method illustrated above. Using Simpson's Rule, the integral of a ...
2answers
2k views

### Use Newton's Method to compute sqrt(x)

Given the following task: Use Newton's method to compute the square root of a number. Newton's method involves successive approximation. You start with a guess, and then continue averaging ...
1answer
4k views

### Fixed point iteration and cobweb plot

I'm using Python to find fixed points of a given function and then draw a cobweb plot to visualize it. Thanks to this question, I have the core of the code written and can accomplish the task, but I ...
6answers
4k views

### Approximating the square root using an iterative method

I wrote this code, based on the Newton-Raphson method, to find the square root of a number. I'm wondering how I can optimise this code, as I am out of ideas. ...
2answers
2k views

### Square root approximations, implemented two ways

Which version is more efficient in calculating the square root ? There are 2 versions I have written to calculate square root programatically. Note reqs strictly state not using library functions ? ...
1answer
3k views

### Python class that implements the Newton method

Here is a python function I wrote to implement the Newton method for optimization for the case where you are trying to optimize a function that takes a vector input and gives a scalar output. I use ...
1answer
91 views

### How can I make this Euler/RK4 implementation more elegant?

One of the things that I'm doing to teach myself is converting some numerical methods from existing Python code (they seem to me to lend themselves to functional programming quite well). I'd like to ...
2answers
26k views

### Trapezoidal rule to approximate the integral of x^2

I've implemented the trapezoidal rule to compute the integral for a function $x^2$. I would like to see another style of the same code. It seems Matlab hates for a matrix to be expanded without ...