【发布时间】:2016-12-19 15:24:34
【问题描述】:
我想知道如何使用方程 ay2 + bxy + cx + dy + e = x2 绘制椭圆轨道?
我首先确定了 a、b、c、d、e 常数,现在我假设通过给出 x 值我将获得 y,这将给我想要的图形,但我无法通过使用 matplotlib 来做到这一点。
如果您能帮助我,我将不胜感激!
编辑:我在这里添加了代码。
from numpy import linalg
from numpy import linspace
import numpy as np
from numpy import meshgrid
import random
import matplotlib.pyplot as plt
from scipy import optimize
x = [1.02, 0.95, 0.87, 0.77, 0.67, 0.56, 0.44, 0.30, 0.16, 0.01]
y = [0.39, 0.32, 0.27, 0.22, 0.18, 0.15, 0.13, 0.12, 0.12, 0.15]
my_list = [] #It is the main list.
b = [0] * len(x) # That is the list that contains the results that are given as x^2 from the equation.
def fxn(): # That is the function that solves the given equation to find each parameter.
global my_list
global b
for z in range(len(x)):
w = [0] * 5
w[0] = y[z] ** 2
w[1] = x[z] * y[z]
w[2] = x[z]
w[3] = y[z]
w[4] = 1
my_list.append(w)
b[z] = x[z] ** 2
t = linalg.lstsq(my_list, b)[0]
print 'List of list representation is', my_list
print 'x^2, the result of the given equation is', b
print '\nThe list that contains the parameters is', t
fxn()
t = linalg.lstsq(my_list, b)[0]
print '\nThe constant a is', t[0]
print 'The constant b is', t[1]
print 'The constant c is', t[2]
print 'The constant d is', t[3]
print 'The constant e is', t[4]
编辑:这里是常量值:
a = -4.10267300566
b = 1.10642410023
c = 0.39735696603
d = 3.05101004127
e = -0.370426134994
【问题讨论】:
-
与您的问题相关(非常相似的问题)stackoverflow.com/questions/29582089/…
-
你能打印出每个常量的值吗?
-
我在 OP 中添加了它们。
-
我正在为您解答。快完成了。
-
干杯!我一直在尝试绘制它几个小时但无法管理,希望它有效!
标签: python matplotlib orbit