|R| Experts
1.04K subscribers
376 photos
35 videos
58 files
205 links
@R_Experts
🔴آمار علم جان بخشیدن به داده‌هاست.
🔷ارتباط با ما
@iamrezaei
لینک یوتیوب و اینستاگرام و ویرگول:
https://zil.ink/expertstv
Download Telegram
#polyroot
تابعی برای یافتن ریشه های چند جمله ای در میدان اعداد حقیقی و مختلط
P(F)
از درجه حداکثر n
که در ان ضرایب چند جمله ای در داخل تابع قرار میگیرند

#Example

10x^5+ 20x^4+5x^3+40


> polyroot(c(40,0,0,5,20,10))
[1] 0.7747767+0.7263645i -0.7747767+1.0830293i -0.7747767-1.0830293i
[4] 0.7747767-0.7263645i -2.0000000+0.0000000i
>


@R_Experts
#Example
install.packages("cubature")
library(cubature)

> testFn0 <- function(x) {
+ prod(cos(x))
+ }
>
> adaptIntegrate(testFn0, rep(0,2), rep(1,2), tol=1e-4)
$integral
[1] 0.7080734

$error
[1] 1.709434e-05

$functionEvaluations
[1] 17

$returnCode
[1] 0



> M_2_SQRTPI <- 2/sqrt(pi)
> testFn1 <- function(x) {
+ scale = 1.0
+ val = 0
+ dim = length(x)
+ val = sum (((1-x) / x)^2)
+ scale = prod(M_2_SQRTPI/x^2)
+ exp(-val) * scale
+ }
>
> adaptIntegrate(testFn1, rep(0, 3), rep(1, 3), tol=1e-4)
$integral
[1] 1.00001

$error
[1] 9.677977e-05

$functionEvaluations
[1] 5115

$returnCode
[1] 0




> testFn2 <- function(x) {
+ ## discontinuous objective: volume of hypersphere
+ radius = as.double(0.50124145262344534123412)
+ ifelse(sum(x*x) < radius*radius, 1, 0)
+ }
>
> adaptIntegrate(testFn2, rep(0, 2), rep(1, 2), tol=1e-4)
$integral
[1] 0.19728

$error
[1] 1.972614e-05

$functionEvaluations
[1] 166141

$returnCode
[1] 0


@R_Experts