numerical-methods

Lennard-Jones potential simulation

泄露秘密 提交于 2019-12-24 15:56:26
问题 import pygame import random import numpy as np import matplotlib.pyplot as plt import math number_of_particles = 70 my_particles = [] background_colour = (255,255,255) width, height = 500, 500 sigma = 1 e = 1 dt = 0.1 v = 0 a = 0 r = 1 def r(p1,p2): dx = p1.x - p2.x dy = p1.y - p2.y angle = 0.5 * math.pi - math.atan2(dy, dx) dist = np.hypot(dx, dy) return dist def collide(p1, p2): dx = p1.x - p2.x dy = p1.y - p2.y dist = np.hypot(dx, dy) if dist < (p1.size + p2.size): tangent = math.atan2(dy,

gnuplot vector arrow length and streamlines

吃可爱长大的小学妹 提交于 2019-12-24 14:00:00
问题 I have already asked about vector fields in here. Now I want to know a bit more about it. How can I make it so that each arrow has the same fixed length and define the magnitude of the value by color? And is it still not possible to plot streamlines in gnuplot? If possible, how can I do that? For now I have this and need to upgrade it. set term pngcairo set title 'Navier-Stokes Equation' set terminal png size 1280,720 set output 'vec.png' plot 'vec' u 1:2:($3/$5):($4/$5) w vec t 'Vector Field

USE DIFFERENTIAL MATRIX OPERATOR TO SOLVE ODE

旧城冷巷雨未停 提交于 2019-12-24 13:11:13
问题 We were asked to define our own differential operators on MATLAB, and I did it following a series of steps, and then we should use the differential operators to solve a boundary value problem: -y'' + 2y' - y = x, y(0) = y(1) =0 my code was as follows, it was used to compute this (first and second derivative) h = 2; x = 2:h:50; y = x.^2 ; n=length(x); uppershift = 1; U = diag(ones(n-abs(uppershift),1),uppershift); lowershift = -1; L= diag(ones(n-abs(lowershift),1),lowershift); % the code above

What's the difference in the use and precision of fsolve, brentq and root for a system of equations?

天大地大妈咪最大 提交于 2019-12-24 12:34:36
问题 I have asked this question Is fsolve good to any system of equations?, from which I got a satisfactory answer. The system I presented there x = A * exp (x+y) y = 4 * exp (x+y) , is just a toy model which is similar with my real case problem, fsolve did the work with (code in the answer below): from scipy.optimize import fsolve import matplotlib.pyplot as plt import numpy as np def f(p,*args): x, y = p A = args[0] return (x -A* np.exp(x+y),y- 4* np.exp(x+y)) A = np.linspace(0,4,5) X = [] Y =[]

how to solve a very large overdetermined system of linear equations?

时光毁灭记忆、已成空白 提交于 2019-12-24 03:19:57
问题 I am doing a project about image processing, and I need to solve the following set of equations: Nx+Nz*( z(x+1,y)-z(x,y) )=0 Ny+Nz*( z(x+1,y)-z(x,y) )=0 and equations of the boundary (bottom and right side of the image): Nx+Nz*( z(x,y)-z(x-1,y) )=0 Ny+Nz*( z(x,y)-z(x,y-1) )=0 where Nx,Ny,Nz are the surface normal vectors at the corresponding coordinates and are already determined. Now the problem is that since (x,y) are the coordinates on an image, which typically has a size of say x=300 and

Python - Multiply sparse matrix row with non-sparse vector by index

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 01:54:50
问题 My current software project involves implementing a numeric method for solving linear systems with python (the so called SOR -Method). It basically works like this: Given a linear system: ax1 + bx2 + cx3 = b1 dx1 + ex2 + fx3 = b2 gx1 + hx2 + ix3 = b3 Re-arrange the equations to: x1_new = (b1 - (bx2 + cx3)) / a x2_new = (b2 - (dx1_new + fx3)) / e x3_new = (b3 - (gx1_new + hx2_new)) / i As you can see, the x*_new values are updating with each line - that's the unfortunate reason why I can't use

Are there any Haskell libraries for integrating complex functions?

帅比萌擦擦* 提交于 2019-12-24 00:58:28
问题 How to numerically integrate complex, complex-valued functions in Haskell? Are there any existing libraries for it? numeric-tools operates only on reals. I am aware that on complex plane there's only line integrals, so the interface I am interested in is something like this: i = integrate f x a b precision to calculate integral along straight line from a to b of function f on point x . i , x , a , b are all of Complex Double or better Num a => Complex a type. Please... :) 回答1: You can make

solving a trig equation numerically with in-browser JS [closed]

空扰寡人 提交于 2019-12-23 20:44:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Given values for the variables s , v , and h , and given a library such as numeric.js how can I numerically solve the following equation for a within a given degree of accuracy? I'm wanting a JS algorithm for use in-browser. 回答1: Separating variables and parameters You could start by substituting b = a/h. That

Finding the elbow point of a curve in a stable way?

落爺英雄遲暮 提交于 2019-12-23 18:37:35
问题 I am aware of the existence of this, and this on this topic. However, I would like to finalize on an actual implementation in Python this time. My only problem is that the elbow point seems to be changing from different instantiations of my code. Observe the two plots shown in this post. While they appear to be visually similar, the value of the elbow point changed significantly. Both the curves were generated from an average of 20 different runs. Even then, there is a significant shift in

The time-corrected Verlet numerical integration formula

我只是一个虾纸丫 提交于 2019-12-23 09:47:49
问题 There is a commonly used verlet-integration formula on the web by Johnathan Dummer, called Time-Corrected Verlet. However I've read several forum posts, that people get weird or unexpected results with it in certain conditions. Formula by Johnathan Dummer: x1 = x + (x – x0) * dt / dt0 + a * dt^2 There is also a stackoverflow answer, which states that Dummer's time-corrected formula is broken and the poster presents his own derivation as the correct one. Suggested correct formula by a