integral

Setting count of decimal digits in printf at runtime in C language

有些话、适合烂在心里 提交于 2020-08-10 23:11:59
问题 I have a number: m which is given by the user as parameter. For example: m = 5 or m = 7 I do not know this at run-time. I then compute an integral and save it to a variable: answer . I want to print answer with m decimals digits. How can I do this? I tried this one: printf("answer = %(%.mf)d ", answer , m); It's wrong ,I know ,but how can I solve it? 回答1: If you have a variable with a value, say: double val = 3.234003467; You could print out to the 2nd decimal place for example using: printf(

Setting count of decimal digits in printf at runtime in C language

我的梦境 提交于 2020-08-10 23:10:13
问题 I have a number: m which is given by the user as parameter. For example: m = 5 or m = 7 I do not know this at run-time. I then compute an integral and save it to a variable: answer . I want to print answer with m decimals digits. How can I do this? I tried this one: printf("answer = %(%.mf)d ", answer , m); It's wrong ,I know ,but how can I solve it? 回答1: If you have a variable with a value, say: double val = 3.234003467; You could print out to the 2nd decimal place for example using: printf(

How to reduce integration time for integration over 2D connected domains

寵の児 提交于 2020-05-07 03:53:10
问题 I need to compute many 2D integrations over domains that are simply connected (and convex most of the time). I'm using python function scipy.integrate.nquad to do this integration. However, the time required by this operation is significantly large compared to integration over a rectangular domain. Is there any faster implementation possible? Here is an example; I integrate a constant function first over a circular domain (using a constraint inside the function) and then on a rectangular

Integration via trapezoidal sums in MATLAB

浪尽此生 提交于 2020-02-05 08:23:49
问题 I need help finding an integral of a function using trapezoidal sums. The program should take successive trapezoidal sums with n = 1, 2, 3, ... subintervals until there are two neighouring values of n that differ by less than a given tolerance. I want at least one FOR loop within a WHILE loop and I don't want to use the trapz function. The program takes four inputs: f : A function handle for a function of x . a : A real number. b : A real number larger than a . tolerance : A real number that

Haskell Converting Int to Float

青春壹個敷衍的年華 提交于 2020-01-21 11:31:07
问题 I'm having some problem with one of the functions which I'm new at, it's the fromIntegral function. Basically I need to take in two Int arguments and return the percentage of the numbers but when I run my code, it keeps giving me this error: Code: percent :: Int -> Int -> Float percent x y = 100 * ( a `div` b ) where a = fromIntegral x :: Float b = fromIntegral y :: Float Error: No instance for (Integral Float) arising from a use of `div' Possible fix: add an instance declaration for

Integration in R with integrate function

大城市里の小女人 提交于 2020-01-16 17:03:49
问题 library(pbivnorm) rho <- 0.5 f1 <- function(x, y) { pbivnorm(log(x)-10, log(y)-10, rho)*(exp(-(log(x)-10)^2/2)/(sqrt(2*pi)*x))*(exp(-(log(y)-10)^2/2)/(sqrt(2*pi)*y)) } integration1 <- round(integrate(function(y) { sapply(y, function(y) { integrate(function(x) f1(x,y), 0, Inf, rel.tol = 1e-12)$value }) }, 0, Inf, rel.tol = 1e-12)$value, 10) This integration should be around 0.3, but R gives 0. Could anyone point out the problem? What is the best function for integral in R? Many thanks. 回答1:

Integration in R with integrate function

此生再无相见时 提交于 2020-01-16 17:03:23
问题 library(pbivnorm) rho <- 0.5 f1 <- function(x, y) { pbivnorm(log(x)-10, log(y)-10, rho)*(exp(-(log(x)-10)^2/2)/(sqrt(2*pi)*x))*(exp(-(log(y)-10)^2/2)/(sqrt(2*pi)*y)) } integration1 <- round(integrate(function(y) { sapply(y, function(y) { integrate(function(x) f1(x,y), 0, Inf, rel.tol = 1e-12)$value }) }, 0, Inf, rel.tol = 1e-12)$value, 10) This integration should be around 0.3, but R gives 0. Could anyone point out the problem? What is the best function for integral in R? Many thanks. 回答1:

How to do numerical multiple integral (more than triple)?

强颜欢笑 提交于 2020-01-07 07:48:42
问题 How to do numerical multiple integral (more than triple) by using Matlab? For example, I have a function,Y = Func. It has 5 var. Hence, Y= func(a,b,c,d,e). If I want to do the integration with respect to a,b,c,d,e. (var a is the first one, e is the last one.) And region of a = [0 ,b] (this is a function handle), b = [0,c], c= [0.d], d= [0,e], e=[0, Inf]. Now, here is my 'real' question. The code is below %%%==== just some parameters ==== a=4; la1=1/(pi*500^2); la2= la1*5; p1=25; p2=p1/25;

Error calculating the area between two lines using “integrate”

﹥>﹥吖頭↗ 提交于 2020-01-07 02:57:05
问题 I'm attempting to calculate the area between two plots using R's integrate function. I have two forecast curves that I'm able to place on the same plot and also shade in the area between the two curves, for visualisation: x1 = seq(1,200,1) y1 = # 200 numbers from 0.02 - 1.000 y2 = # 200 numbers from 0.00 - 0.95 plot(x1,y1,type="l",bty="L",xlab="Forecast Days",ylab="Curve Actuals") points(x1,y2,type="l",col="red") polygon(c(x1,rev(x1)),c(y2,rev(y1)),col="skyblue") Following the example here

Converting hard integral to lambda function with lambdify

人走茶凉 提交于 2020-01-02 05:36:09
问题 I would like to lambdify the function Integral(t**t,(t,0,x)) . It works, but my new function, which was returned by lambdify , doesn't return a number but only sympy.integrals.integrals.Integral class. But I don't want that, I want it to return a float number. Here is my code: import sympy as sp import numpy as np f = sp.lambdify(x,sp.integrate(t**t,(t,0,x))) print(f(2)) #return Integral(t**t, (t, 0, 2)) #but i want 2.83387674524687 回答1: lambdify doesn't support scipy.integrate.quad directly