numerical-methods

Converting a recursive formula back to the original explicit formula?

六月ゝ 毕业季﹏ 提交于 2019-12-23 06:08:44
问题 There is a generic formula Z^N = A(Z)^N+1 + B(Z)^N+1 . This formula is used to convert a given recursive function back to its original explicit form : Recursive Formulas : 1) R(0) = 1, R(n) = (1/3) R(n-1), n = 1, 2, ... 2) P(0) = 1, P(1) = 1/3, P(n) = (4/3) P(n-1) - (1/3) P(n-2), n = 2, 3, ... 3) Q(0) = 1, Q(1) = 1/3, Q(n) = (10/3) Q(n-1) - Q(n-2), n = 2, 3, ... Then, it suggests that "difference formulas" of the form : 2) P(n) = A(1/3^n) + B 3) Q(n) = A(1/3^n) + B * 3^n represent the general

Numerical grouping using matlab / octave and not repeating values found in main array

此生再无相见时 提交于 2019-12-23 02:31:24
问题 I have about 100,000 numbers that I would like to group together based on dividing by two or increments of two. PS: The increment values may change and the values found in the main array "x" can only be used once. I'm not sure how to check and stop the loop if a number in the "array_all" array has been repeated from the "x" array. See example below Example: x=[9,8,7,6,5,4,3,2,1] I'm trying to get the array_all array to look like this: array_all= [ 9.00000 4.50000 2.25000 8.00000 4.00000 2

Multiprocessing with Screen and Bash

我的未来我决定 提交于 2019-12-22 09:00:06
问题 Running a python script on different nodes at school using SSH. Each node has 8 cores. I use GNU Screen to be able to detach from a single process. Is it more desirable to: Run several different sessions of screen. Run a single screen process and use & in a bash terminal. Are they equivalent? I am not sure if my experiments are poorly coded and taking an inordinate amount of time (very possible) OR my choice to use 1. is slowing the process down considerably. Thank you! 回答1: With bash I

Simpson's rule in Python

泪湿孤枕 提交于 2019-12-21 17:08:32
问题 For a numerical methods class, I need to write a program to evaluate a definite integral with Simpson's composite rule. I already got this far (see below), but my answer is not correct. I am testing the program with f(x)=x, integrated over 0 to 1, for which the outcome should be 0.5. I get 0.78746... etc. I know there is a Simpson's rule available in Scipy, but I really need to write it myself. I suspect there is something wrong with the two loops. I tried "for i in range(1, n, 2)" and "for i

Avoiding numerical overflow when calculating the value AND gradient of the Logistic loss function

╄→гoц情女王★ 提交于 2019-12-21 16:53:31
问题 I am currently trying to implement a machine learning algorithm that involves the logistic loss function in MATLAB. Unfortunately, I am having some trouble due to numerical overflow. In general, for a given an input s , the value of the logistic function is: log(1 + exp(s)) and the slope of the logistic loss function is: exp(s)./(1 + exp(s)) = 1./(1 + exp(-s)) In my algorithm, the value of s = X*beta . Here X is a matrix with N data points and P features per data point (i.e. size(X)=[N,P] )

Javascript numerical library - vectors, matrices, determinates, inversion

风流意气都作罢 提交于 2019-12-20 10:46:57
问题 Is there a reasonable numerical library in pure JavaScript? I'd like array-based vectors, matrices, determinate, and matrix inversion. This is only for small problems, not big ones. I'm aware there are choices in Python, Java, C++, or, oh, perhaps FORTRAN, not to mention R. mmm....FORTRAN...... I'd be happily surprised to get basic vector and matrix operations without having to rebuild the wheel or recode from FORTRAN for a day or two. 回答1: Maybe also of interest: http://www.numericjs.com/

Runge Kutta problems in JS

て烟熏妆下的殇ゞ 提交于 2019-12-19 10:26:20
问题 I'm attempting a Runge-Kutta implementation for a mass on a spring in Javascript and visualizing it with D3. The purpose is to compare it to Forward Euler and comment on the differences. My FE works fine and plots fine, but the Runge-Kutta is shooting off in a negative direction and never wrapping around. Here's a plunkr with the vis and the code, but I'll add the JS (only for the ODE solvers) too. // *** Functions for ODE Solvers *** // function FEx (x, v, h) { return x + h*v; } function FEv

Minimum finding for univariate nonlinear function in Java

倖福魔咒の 提交于 2019-12-19 09:28:14
问题 I'm looking for a simple way to accomplish in Java what MATLAB's fminsearch() does. I don't need to be as general as fminsearch, in my case I only want to find the minimum (function and parameter values at minimum) of a single-variable nonlinear function. I don't know the analytical expression of the function, but I can evaluate it easily. Do you know of a library that performs this, or of an easy algorithm I could re-implement? Note: I saw that apache's common-math seems to have something

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

心不动则不痛 提交于 2019-12-19 05:11:29
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . 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

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

喜夏-厌秋 提交于 2019-12-19 05:10:28
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . 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