calculus

scipy.integrate.quad precision on big numbers

我们两清 提交于 2019-12-20 03:45:10
问题 I try to compute such an integral (actually cdf of exponential distribution with its pdf) via scipy.integrate.quad() : import numpy as np from scipy.integrate import quad def g(x): return .5 * np.exp(-.5 * x) print quad(g, a=0., b=np.inf) print quad(g, a=0., b=10**6) print quad(g, a=0., b=10**5) print quad(g, a=0., b=10**4) And the result is as follows: (1.0, 3.5807346295637055e-11) (0.0, 0.0) (3.881683817604194e-22, 7.717972744764185e-22) (1.0, 1.6059202674761255e-14) All the attempts to use

Ploting solid of revolution in Python 3 (matplotlib maybe)

微笑、不失礼 提交于 2019-12-19 03:43:11
问题 Greetings the problem: R is a region in the xy plane bounded by the parabola y=x^2+1 and line y=x+3. A solid of revolution is formed by rotating R around the x axis. I need to plot parabola and line in 2D and solid revolution 3D, How do it? I have installed anaconda. 回答1: You could use plot_surface: import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d.axes3d as axes3d fig = plt.figure() ax = fig.add_subplot(1, 1, 1, projection='3d') u = np.linspace(-1, 2, 60) v = np

MATLAB: How do I pass a parameter to a function?

为君一笑 提交于 2019-12-17 16:30:39
问题 I have the following function: function ypdiff = ypdiff(t,y) a = 0.01; b = 0.1; ypdiff(1) = -a*y(1)*y(2); ypdiff(2) = b*y(1)*y(2)-b*y(2); ypdiff(3) = b*y(2); ypdiff = [ypdiff(1) ypdiff(2) ypdiff(3)]'; If I want to solve this, I would call the ode45 function as follows: [t y] = ode45(@ypdiff, [to tf], yo); But if I want to pass a parameter to this function, how would I use the ode45 function? Specifically, I am trying for the following formulation: function ypdiff = ypdiff(t,y,u) a = 0.01; b =

Re: Space physics for missiles, spaceships

Deadly 提交于 2019-12-13 17:36:56
问题 In this rather useful CodeProject article, an enterprising and very helpful person has done the math needed for a newtonian missile to hit a newtonian target (it also works for matching course and speed between spaceships, with a bit of fiddling of inputs). One of the things I've written with this in the past is a battle between up to hundreds of spaceships (blocks), firing missiles (blocks) at each other. Quite neat. However, it only works for purely newtonian craft and, as anyone who's paid

Calculating the boundary of irregular shape in Cartesian Coordinate 2D

青春壹個敷衍的年華 提交于 2019-12-13 14:25:29
问题 I'm looking for a solution to calculate the boundary of an irregular shape. Lats take a look at Square example: if i have Minimum x and y and Maximum x and y like: MaxX = 5 MinX = 1 MaxY = 5 MinY = 1 in python language: #Python Code X = {"Min":1, "Max":5} # is Dictionary of x Axis Y = {"Min":1, "Max":5} # is Dictionary of y Axis I can check if any coordinate is in the square boundary or not, simpley by comparing the axis against min and max of square boundary. now let's look at these 2

PROC IML trapezoidal rule

本小妞迷上赌 提交于 2019-12-13 08:34:31
问题 proc iml; start tr(x,y); * create function called tr; N = nrow(x); dx = x[2:N] - x[1:N-1]; ymean = (y[2:N] + y[1:N-1]) / 2; return(dx` * ymean ); finish tr; x = do(-2,5,0.01); print "Integral of a over x is" ( tr(x,0#x+1) ); *Answer is 7; I keep receiving the (execution) invalid subscript or subscript out of range. How do I solve this problem and get the correct answer? I've tried taking out the -1 in x[1:N-1]; and y[1:N-1], but it gives me the wrong answer. Is it because I need to assume

Python Matplotlib Quiver wrong orientation

让人想犯罪 __ 提交于 2019-12-13 03:43:27
问题 Im creating an ipython notebook on vector calculus. (Basics, at least). On this block of code im trying to have a pseudocolor plot of the function x^2 + XY + Y^2 and plot over it the vector field given by its gradient U = 2X+Y and V = 2Y+X However the quiver plot appears to be rotated 90 degrees, therefore not pointing in the right direction x = arange(-2.0, 2.0,00.1) y = arange(-2.0, 2.0,00.1) X,Y = meshgrid(x, y) Z = X**2 + X*Y + Y**2 GradX = (2*X+Y) GradY = (2*Y+X) figure(figsize=(10, 10))

Finding rotation of 3 given lines in 3D until intersection with 3 other given lines

。_饼干妹妹 提交于 2019-12-13 02:31:14
问题 I have a matlab code with 3 equations and 3 variables that I'm trying to solve (and don't succeed). The equations are symbolic with three unknown variables x,y,z and the rest of the symbols are known. I need to find the values of x,y,z as expressions of the other known symbols. Here's the matlab code: clear; close all; clc; %unknown variables syms x y z %The angles of rotations (in radians) %known symbols syms px1 py1 pz1 %point on line1 set1 syms px2 py2 pz2 %point on line2 set1 syms px3 py3

Exemplar-Based Inpainting - how to compute the normal to the contour and the isophate

十年热恋 提交于 2019-12-12 10:20:48
问题 I am using the Exemplar-Based algorithm by Criminisi. In section 3 of his paper it describes the algorithm. The target region that needs to be inpainted is denoted as Ω (omega). The border or the contour of Ω where it meets the rest of the image (denoted as Φ (phi)), is δΩ (delta omega). Now on page four of the paper, it states that np (n subscript p) is the normal to the contour of δΩ . and ▽Ip (also includes orthogonal superscript) is the isophote at point p , which is the gradient turned

Using QScriptEngine to compute calculations

亡梦爱人 提交于 2019-12-11 19:24:23
问题 I'm creating a diagram modeling tool that connects Items to Tasks . Items have Properties (simple name/value relationships) and Tasks have Formulas . I intend to produce a UI for the users to write in a QLineEdit a formula using C++ syntax ( ie, (property1 * property2)/property3 ), and then output the result. Of course, the formula would have to be somehow parsed and computed to output the result. My concern with this is if using QScriptEngine is appropriate for this. I've seen that it can be