考虑一个函数f(t),我如何计算连续的Fouriertransform g(w)并绘制它(使用numpy和matplotlib)?

如果不存在傅里叶积分的解析解,则出现这个或反问题(g(w)给出,f(t)未知的图).
我有一个Latex文件,其中标记了很多文本\red{},但是里面也可能有括号\red{},比如\red{here is \underline{underlined} text}.我想删除红色,经过一些谷歌搜索,我写了这个python脚本:
import os, re, sys
#Start program in terminal with
#python RedRemover.py filename
#sys.argv[1] then has the value filename
ifn = sys.argv[1]
#Open file and read it
f = open(ifn, "r")
c = f.read()
#The whole file content is now stored in the string c
#Remove occurences of \red{...} in c
c=re.sub(r'\\red\{(?:[^\}|]*\|)?([^\}|]*)\}', r'\1', c)
#Write c into new file
Nf=open("RedRemoved_"+ifn,"w")
Nf.write(c)
f.close()
Nf.close()
Run Code Online (Sandbox Code Playgroud)
但这将转换
\ red {here is\underline {underlined} text}
至 …
当我在matplotlib中绘制函数时,绘图由矩形框起.我希望这个矩形的长度和高度的比率由黄金均值给出,即dx/dy = 1.618033 ......
如果x和y标度是线性的,我使用谷歌找到了这个解决方案
import numpy as np
import matplotlib.pyplot as pl
golden_mean = (np.sqrt(5)-1.0)/2.0
dy=pl.gca().get_ylim()[1]-pl.gca().get_ylim()[0]
dx=pl.gca().get_xlim()[1]-pl.gca().get_xlim()[0]
pl.gca().set_aspect((dx/dy)*golden_mean,adjustable='box')
Run Code Online (Sandbox Code Playgroud)
如果是对数日志图,我想出了这个解决方案
dy=np.abs(np.log10(pl.gca().get_ylim()[1])-np.log10(pl.gca().get_ylim()[0]))
dx=np.abs(np.log10(pl.gca().get_xlim()[1])-np.log10(pl.gca().get_xlim()[0]))
pl.gca().set_aspect((dx/dy)*golden_mean,adjustable='box')
Run Code Online (Sandbox Code Playgroud)
但是,对于半对数图,当我调用set_aspect时,我得到了
UserWarning: aspect is not supported for Axes with xscale=log, yscale=linear
Run Code Online (Sandbox Code Playgroud)
任何人都可以想到解决这个问题吗?
我在 matplotib 中使用 'text.usetex': True 。这对于具有线性比例的图来说非常有用。然而,对于对数刻度,y 刻度如下所示:

指数中的负号占用了绘图中的大量水平空间,这不太好。我希望它看起来像这样:

该字体来自 gnuplot,并且没有使用 tex-font。我想使用 matplotlib,将其呈现在 tex 中,但 10^{-n} 中的减号应该更短。那可能吗?
我有一个带动态数组(DA)的类
class DA{
private:
double* array;
int size N;
//other stuff
public:
DA(){
array=NULL;
}
DA(int PN){
N=PN;
array=new double[N];
};
//destructor and other stuff
}
Run Code Online (Sandbox Code Playgroud)
这似乎没问题.现在我想要一个具有一个DA对象的类"Application":
class App{
private:
DA myDA;
public:
App(int N){
//create myDA with array of size N
DA temp(N);
myDA=temp;
};
}
Run Code Online (Sandbox Code Playgroud)
问题是,我不知道如何在App构造函数中创建myDA.我这样做,内存分配给temp,然后myDA指向temp.但我想在构造函数完成后删除为temp分配的内存.因此,当我执行程序时出现内存错误.那么如何正确分配内存呢?
python ×4
matplotlib ×3
fft ×2
numpy ×2
allocation ×1
aspect-ratio ×1
c++ ×1
dynamic ×1
latex ×1
logarithm ×1
math ×1
memory ×1
physics ×1
regex ×1