numerical-methods

Using odeint function definition

北城余情 提交于 2019-12-01 08:40:55
Pretty noob question so please bear with me. I am following the example given here--> http://www.codeproject.com/Articles/268589/odeint-v2-Solving-ordinary-differential-equations In particular, I am looking at this function: void lorenz( state_type &x , state_type &dxdt , double t ) { dxdt[0] = sigma * ( x[1] - x[0] ); dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; dxdt[2] = x[0]*x[1] - b * x[2]; } In my case, R takes on a series of values (vector with 100 doubles). odeint is called as: integrate_const( runge_kutta4< state_type >() , lorenz , x , 0.0 , 10.0 , dt ); I would like to do this for each

odeint streaming observer and related questions

蓝咒 提交于 2019-12-01 06:30:51
问题 I have a system of 4 coupled equations to solve and a parameter Gamma[i] to iterate over. Since I am quite new to C++, my code is a very rudimentary. If it looks sophisticated and elegant in certain parts, it is only because I have adapted code from the author of odeint. :) This question is related to (http://stackoverflow.com/questions/12060111/using-odeint-function-definition/12066958#comment16253600_12066958) but not exactly the same. Please do not delete this. :( Questions have been

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

ⅰ亾dé卋堺 提交于 2019-12-01 06:21:56
问题 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>

Frequently Updating Stored Data for a Numerical Experiment using Python [closed]

一个人想着一个人 提交于 2019-12-01 01:52:57
I am running a numerical experiment that requires many iterations. After each iteration, I would like to store the data in a pickle file or pickle-like file in case the program times-out or a data structure becomes tapped. What is the best way to proceed. Here is the skeleton code: data_dict = {} # maybe a dictionary is not the best choice for j in parameters: # j = (alpha, beta, gamma) and cycle through for k in number_of_experiments: # lots of experiments (10^4) file = open('storage.pkl', 'ab') data = experiment() # experiment returns some numerical value # experiment takes ~ 1 seconds, but

Accept Numerical Values only for input using scanf

*爱你&永不变心* 提交于 2019-11-30 23:31:53
How can I make sure the user inputs numerical values only instead of alphanumeric or any other character? Also what to look for to insert error message for incorrent input? #include<stdio.h> int main() { int a, b, c; printf("Enter first number to add\n"); scanf("%d",&a); printf("Enter second number to add\n"); scanf("%d",&b); c = a + b; printf("Sum of entered numbers = %d\n",c); return 0; } If you really want to deal with user input that could be hostile use a separate function for getting the number. Allows - leading spaces : " 123" - trailing spaces : "123 " - leading zeros :

c# - solving complexed ODE set

我的梦境 提交于 2019-11-30 20:41:30
问题 Introduction Some sets od ODE can't be solved analytically. In this case there are plenty of well-know methods, especially in typical scientific software like MATLAB. As long as you stay with it, all is fine. But the problem starts if you try to port this functionality to other environment. In my case I need it in C#. Some details Of course, there are some C# libs for ODE's but in most cases (at least in this which i'm familiar with), there are quite limited. Let's look at OSLO library, here

What's the numerically best way to calculate the average

╄→гoц情女王★ 提交于 2019-11-30 08:11:36
what's the best way to calculate the average? With this question I want to know which algorithm for calculating the average is the best in a numerical sense. It should have the least rounding errors, should not be sensitive to over- or underflows and so on. Thank you. Additional information: incremental approaches preferred since the number of values may not fit into RAM (several parallel calculations on files larger than 4 GB). You can have a look at http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.43.3535 (Nick Higham, "The accuracy of floating point summation", SIAM Journal of

numerical partial derivative in MatLab

别说谁变了你拦得住时间么 提交于 2019-11-30 06:02:53
问题 How can I compute the numerical partial derivative of a probability density function (PDF) in Matlab? I'm not looking for a solution using automatic differences or a symbolic solution. Given the following example: arg = (-1:.01:1)'; mu = 0; sigma = 0.5; f = normpdf(arg,mu,sigma); Is it possible to compute the numerical partial derivative of df/dsigma ? Or am I stuck to having to use the automatic differences or the Symbolic Math toolbox? 回答1: I assume that the actual function is not the PDF

Numerical ODE solving in Python

戏子无情 提交于 2019-11-30 05:04:38
How do I numerically solve an ODE in Python? Consider \ddot{u}(\phi) = -u + \sqrt{u} with the following conditions u(0) = 1.49907 and \dot{u}(0) = 0 with the constraint 0 <= \phi <= 7\pi. Then finally, I want to produce a parametric plot where the x and y coordinates are generated as a function of u. The problem is, I need to run odeint twice since this is a second order differential equation. I tried having it run again after the first time but it comes back with a Jacobian error. There must be a way to run it twice all at once. Here is the error: odepack.error: The function and its Jacobian

Fast algorithm to calculate Pi in parallel

强颜欢笑 提交于 2019-11-30 04:46:41
I am starting to learn CUDA and I think calculating long digits of pi would be a nice, introductory project. I have already implemented the simple Monte Carlo method which is easily parallelize-able. I simply have each thread randomly generate points on the unit square, figure out how many lie within the unit circle, and tally up the results using a reduction operation. But that is certainly not the fastest algorithm for calculating the constant. Before, when I did this exercise on a single threaded CPU, I used Machin-like formulae to do the calculation for far faster convergence. For those