gpt4 book ai didi

python - 反正弦的变体

转载 作者:行者123 更新时间:2023-11-30 23:28:03 24 4
gpt4 key购买 nike

如何改变反正弦?

我在做

q1=np.linspace(0, 90, 91)
n1=1
n2=1.5
q2=math.asin(n1*sin(q1)/n2)

但是它不起作用。

最佳答案

您正在寻找这样的东西吗?

>>> import numpy as np
>>> q1 = np.linspace(0, 90, 91)
>>> n1 = 1.0
>>> n2 = 1.5
>>> q2 = np.arcsin(n1 * np.sin(q1)/n2)
>>> q2
array([ 0. , 0.59556994, 0.65127169, 0.09421935, -0.5288433 ,
-0.69356529, -0.18737145, 0.45336277, 0.72024942, 0.27832517,
-0.37114289, -0.7297189 , -0.36582013, 0.28391011, 0.72135785,
0.44840107, -0.19313398, -0.69571139, -0.52435893, 0.10008515,
0.65433303, 0.59169712, -0.00590091, -0.59939972, -0.64815789,
-0.08834939, 0.53329356, 0.69135801, 0.18160037, -0.45829823,
-0.71907338, -0.27272678, 0.37644614, 0.72964882, 0.36047826,
-0.28948127, -0.7223984 , -0.44341358, 0.19888767, 0.6977958 ,
0.51984095, -0.10594654, -0.65734134, -0.58778184, 0.01180156,
0.60318587, 0.64499223, 0.08247555, -0.53770916, -0.68909002,
-0.17582103, 0.46320699, 0.71783003, 0.26711526, -0.38172949,
-0.7295087 , -0.35511764, 0.29503831, 0.72337079, 0.43840076,
-0.20463223, -0.69981805, -0.51528991, 0.11180324, 0.66029604,
0.58382468, -0.01770169, -0.60692782, -0.64177529, -0.07659809,
0.54208958, 0.68676185, 0.17003371, -0.46808859, -0.7165197 ,
-0.26149094, 0.38699256, 0.72929856, 0.34973866, -0.3005809 ,
-0.72427477, -0.43336304, 0.21036737, 0.70177767, 0.5107063 ,
-0.117655 , -0.66319655, -0.57982621, 0.02360106, 0.61062497,
0.63850766])

在您的原始代码中,至少存在两个问题。第一,math.asin是内置数学 sin函数,并且它仅对标量进行操作,而不对 numpy 进行操作数组。二、您引用sin(q1) ,只有导入 numpy.sin 才有效。使用 from numpy import sin 进入范围或者其他的东西。 [有时人们会from numpy import * ,但这是一个坏主意,因为它破坏了一些有用的内置函数。]

关于python - 反正弦的变体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21833635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com