我在那里使用Octave 2.3.4和绘图命令.我是Octave的新人.由于某种原因,此图不显示.这是我的M文件样本:
1;
clear all;
%%%%%%%%% parameters setting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
r=0.01; %risk free rate
S0=50; %underlying price 1
%create an implied volatiltiy surface using below parameters:
basevol=0.25; %implied volatility at time t=0 and in center of strike axis
skewT=-0.001; %icrease in vol for one unit increase in maturity
v1=0.1; %defines how much a smile is raised at left end from base vol
v3=0.2; %defines how much a smile is raised at right end from base vol
nK=100; %no. of strike steps …Run Code Online (Sandbox Code Playgroud) 基本上我试图找到矩阵的特征值,大约需要12个小时.当它完成时,它说它找不到所有的特征向量(实际上几乎没有),而且我对它找到的那些特征向量持怀疑态度.我所能做的就是发布我的代码,我希望有人可以向我提出一些建议.我对mathematica不太熟悉,也许运行时间慢,结果不好与我有关,而不是mathematica的能力.感谢任何回复的人,我真的很感激.
cutoff = 500; (* set a cutoff for the infinite series *)
numStates = cutoff + 1; (* set the number of excited states to be printed *)
If[numStates > 10, numStates = 10];
$RecursionLimit = cutoff + 256; (* Increase the recursion limit to allow for the specified cutoff *)
(* set the mass of the constituent quarks *)
m1 := mS; (* just supposed to be a constant *)
m2 := 0;
(* construct the hamiltonian *) …Run Code Online (Sandbox Code Playgroud) 我是 ROS 的新手……并试图创建一个简单的随机数生成器,它将发布随机生成的值。为此,我创建了一个 Position 类:
include "stdlib.h"
namespace RandomPositionGenerator {
class Position {
private:
double x;
double y;
double z;
public:
Position();
void setPosition();
void getPosition(double &a, double &b, double &c);
};
Position::Position(){}
void Position::setPosition() {
x = rand();
y = rand();
z = rand();
}
void Position::getPosition(double &a, double &b, double &c) {
a=x;
b=y;
c=z;
}
}
Run Code Online (Sandbox Code Playgroud)
并使用这个类来创建我的发布者:
include "ros/ros.h"
include "std_msgs/String.h"
include "sstream"
include "Position.cpp"
/**
* This method generates position coordinates at random.
**/
int main(int …Run Code Online (Sandbox Code Playgroud) 我如何防止从随机数重复数字.我需要在1到9之间生成5个不同的数字.我经常会得到像23334这样的数字,我该如何防止?任何帮助都会很棒!
int num2 = (int) Math.round((Math.random()*9) +1);
int num1 = (int) Math.round((Math.random()*9) +1);
int num5 = (int) Math.round((Math.random()*9) +1);
int num3 = (int) Math.round((Math.random()*9) +1);
int num4 = (int) Math.round((Math.random()*9) +1);
Run Code Online (Sandbox Code Playgroud) 如果不想使用零初始化向量,是否浪费时间?
我尝试以下代码:
#include <iostream>
#include <vector>
#include <array>
#define SIZE 10
int main()
{
#ifdef VECTOR
std::vector<unsigned> arr(SIZE);
#else
std::array<unsigned, SIZE> arr;
#endif // VECTOR
for (unsigned n : arr)
printf("%i ", n);
printf("\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出:
与矢量
$ g++ -std=c++11 -D VECTOR test.cpp -o test && ./test
0 0 0 0 0 0 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
与数组
g++ -std=c++11 test.cpp -o test && ./test
-129655920 32766 4196167 0 2 0 4196349 0 1136 0
Run Code Online (Sandbox Code Playgroud)
我也尝试使用clang ++
那为什么要零呢?顺便说一句,我可以不初始化就声明一个向量吗?
基本上我正在尝试检查程序被调用时是否有任何东西在stdin中,所以如果我有另一个名为output的文件写入stdout然后
./output | ./program应该工作并且./program应该退出并出错
我已经尝试了越来越多的时间,但我得到了同样的错误.当我使用外部lib时,例如我尝试使用openssl和crypto ++,我收到错误:"undefined reference to(function)".
我不知道为什么Eclipse会这样做,因为#include都是正确的.我甚至尝试过添加Properties-C/C++ General-Path&Symbols的路径,但什么都没有.
有谁能够帮我?
我将一些简单的IDL代码传递给Python.但是,从SciPy/NumPy包中返回的FFT值与IDL包不同,我无法找到原因.
这一切减少到8种元素的一个简单的例子,我发现,SciPy的/ NumPy的例程返回比IDL那些(归一化的问题,我想)更大8(2 ^ 3)倍的值.
以下是两种语言的示例代码(从此处复制):
signal = ([-2., 8., -6., 4., 1., 0., 3., 5.])
fourier = fft(signal)
print, fourier
Run Code Online (Sandbox Code Playgroud)
回报
(1.62500,0.00000)(0.420495,0.506282)(0.250000,0.125000)(-1.17050,-1.74372)(-2.62500,-0.00000)(-1.17050,1.74372)(0.250000,-0.125000)(0.420495,-0.506282)
from scipy.fftpack import fft
import numpy as N
…
signal = N.array([-2., 8., -6., 4., 1., 0., 3., 5.])
fourier = fft(signal)
print fourier
Run Code Online (Sandbox Code Playgroud)
回报
[13. + 0.j,3.36396103 + 4.05025253j,2.+ 1.j,-9.36396103-13.94974747j,-21.+ 0.j,-9.36396103 + 13.94974747j,2.-1.j,3.36396103 -4.05025253j]
我用NumPy包做到了,得到了相同的结果.我也试过print fft(signal, 8 )以防万一,但它返回了同样的,如预期的那样.
然而,并非所有,回到我真正的256个元素阵列,我发现差异不再是8或256,而是256*8!这只是疯了.
虽然我解决了这个问题,但我需要知道为什么会有这种差异.
解决了:这只是规范化,在某些时候我将IDL 256阵列分成8倍,我忘了删除.在Dougal的回答中,有我错过的文档.
这个问题是在朋友发表评论之后提出的.他说,当一个查询有很多子查询时,这是一个信号,表明数据库存在设计缺陷,必须避免这些缺陷.他还说很多书都有同样的建议.
我部分同意,但我认为这些查询具有复杂的逻辑,需要大量子查询,或者,为了避免子查询,查询的物化视图或大量数据冗余.
那么,子查询的真相是什么?他们必须始终避免吗?没问题吗?他们是否表明数据库设计存在缺陷?是否有可能使数据库设计允许复杂的查询而不需要数据冗余?
我正在将一些代码从 IDL 移到 python 中。一个 IDL 调用是 INT_TABULATE,它在固定范围内执行积分。
INT_TABULATED 函数使用五点 Newton-Cotes 积分公式对闭区间 [MIN(x) , MAX(x)] 上的一组表格数据 { xi , fi } 进行积分。
Result = INT_TABULATED( X, F [, /DOUBLE] [, /SORT] )
结果是曲线下的面积。
我的问题是,Numpy/SciPy 是否提供了类似的集成形式?我看到它[scipy.integrate.newton_cotes]存在,但它似乎返回“牛顿-科特斯积分而不是面积的权重和误差系数”。