我写了一个Java程序来计算Riemann Zeta函数的值.在程序内部,我创建了一个库来计算必要的复杂函数,如atan,cos等.两个程序中的所有内容都通过double和BigDecimal数据类型访问.这在评估Zeta函数的大值时会产生重大问题.
Zeta函数参考的数值近似
在s具有较大复杂形式的情况下,以高值直接评估此近似会产生问题,例如s = (230+30i).我非常感谢在这里获得有关这方面的信息.S2.minus(S1)由于我在adaptiveQuad方法中写错了,因此创建错误的评估.
例如,Zeta(2+3i)通过这个程序生成
Calculation of the Riemann Zeta Function in the form Zeta(s) = a + ib.
Enter the value of [a] inside the Riemann Zeta Function: 2
Enter the value of [b] inside the Riemann Zeta Function: 3
The value for Zeta(s) is 7.980219851133409E-1 - 1.137443081631288E-1*i
Total time taken is 0.469 seconds.
Run Code Online (Sandbox Code Playgroud)
这是正确的. …
我希望用Java编写一个方法,找到连续函数的导数.这些是对该方法做出的一些假设 -
例如,函数cos(x)可以显示为0,pi,2pi,3pi,... npi的最大值或最小值.
我正在寻找一个方法,它将找到所有这些最大值或最小值,只要给出函数,lowerBound,upperBound和步长.
为了简化我的测试代码,我为cos(x)编写了一个程序.我使用的函数与cos(x)非常相似(至少在图形上).这是我写的一些测试代码 -
public class Test {
public static void main(String[] args){
Function cos = new Function ()
{
public double f(double x) {
return Math.cos(x);
}
};
findDerivative(cos, 1, 100, 0.01);
}
// Needed as a reference for the interpolation function.
public static interface Function {
public double f(double x);
}
private static int sign(double x) {
if (x < 0.0)
return -1;
else if (x > 0.0) …Run Code Online (Sandbox Code Playgroud) 注意:2015年6月17日更新.当然这是可能的.请参阅以下解决方案.
即使有人复制并粘贴此代码,您仍然需要进行大量清理工作.另请注意,从Re(s)= 0到Re(s)= 1 :),关键条带内部会出现问题.但这是一个好的开始.
import java.util.Scanner;
public class NewTest{
public static void main(String[] args) {
RiemannZetaMain func = new RiemannZetaMain();
double s = 0;
double start, stop, totalTime;
Scanner scan = new Scanner(System.in);
System.out.print("Enter the value of s inside the Riemann Zeta Function: ");
try {
s = scan.nextDouble();
}
catch (Exception e) {
System.out.println("You must enter a positive integer greater than 1.");
}
start = System.currentTimeMillis();
if (s <= 0)
System.out.println("Value for the Zeta Function = " + …Run Code Online (Sandbox Code Playgroud) 我在Java中写一个无限的和匹配 -
sqrt(t)*sech(t)^2 dtfrom t=0to t=infinity(无限和从开始t = 0然后结束t = infinity.我正在引用Wolfram Alpha(Mathematica)来比较我的结果).
在更多的数学术语中,这(基本上)是程序正在做的事情.我注意到这是平方(双曲线)割线.虽然,最大值实际上是无限的 -
integrate sqrt(t)*sech(t)^2 dt from t=0 to t=1000
Run Code Online (Sandbox Code Playgroud)
为了匹配这个无限的总和,我在下面写了一个简短的程序.
public class TestSum {
public static void main(String[] args) {
newForm(0.5);
}
public static double newForm(double s) {
int n = 0;
double currentSum = 0;
while (n < 1000) {
double sech = 1 / Math.cosh(n);
double squared = Math.pow(sech, 2);
currentSum = ((Math.pow(n, s))*squared) + currentSum;
if(n == 999)
System.out.println("The …Run Code Online (Sandbox Code Playgroud) 我按照本文中的实现创建了下面的 Matlab 代码来实现欧式看跌期权的价值。我试图绘制 M 的值与欧洲看跌期权的值的关系图,其中 M 以 5 的时间步长从 20 增加到 250。
为了做到这一点,我创建了一个 for 循环来更改 M 的值,
for M = 20:5:250
Run Code Online (Sandbox Code Playgroud)
我认为我需要创建这个 for 循环才能更改 M 的值。单元测试表明我做错了。for 循环未按预期工作。代码生成的图表引用 M 的原始值(定义为 200),而不是 for 循环内 M 的变化值。我不知道为什么代码返回 M 的原始值而不是 for 循环内的值。
clear all;
close all;
% EURO9 Binomial method for a European put.
%
% Uses explicit solution based on binomial expansion.
% Vectorized, based on logs to avoid overflow,
% and avoids computing with zeros.
%%%%%%%%%% Problem and method parameters %%%%%%%%%%%%% …Run Code Online (Sandbox Code Playgroud)