ich bin neu im Bereich der Python Programmierung und habe den folgenden Code geschrieben.
Den "gleichen" Code habe ich in Matlab bereits erfolgreich geschrieben.
Ich habe folgendes Problem. Wenn ich die Inkrementierung von phi_12+=0.01 auf phi_12+=0.1 ändere, dann klappt es. Jedoch ist dann der Plot falsch, da das Programm eine Inkrementierung von mind 0.01 benötigt. Wenn ich den Wert auf 0.01 belasse, dann erhalte ich kein Ergebnis bzw. das Programm kommt nicht zum Ende.
Kann mir einer sagen, was an dem Quellcode falsch ist?
Code: Alles auswählen
import numpy as np
import math
import matplotlib.pyplot as plt
L_1=150 #Ausgemessen
L_2=40 #Ausgemessen
L_3=140 #Ausgemessen
L_4=56 #Ausgemessen
phi_12=0 #start condition aus CAD
phi_23=(83.87/180)*math.pi #Startbedingung aus CA
phi_34=(168.88/180)*math.pi #Startbedingung aus CAD
winkel1=[]
winkel2=[]
while phi_12<math.pi*2:
while 1:
J = np.array([[-L_3*math.sin(phi_23),L_3*math.cos(phi_23)],[-L_4*math.sin(phi_34),-L_4*math.sin(phi_34)]]) # Creates a matrix.
f_1=np.array([-L_2*math.cos(phi_12)-L_3*math.cos(phi_23)-L_4*math.cos(phi_34), L_1-L_2*math.sin(phi_12)-L_3*math.sin(phi_23)-L_4*math.sin(phi_34)])
dphi=np.linalg.solve(J,f_1) # Solve the linear equation system.
#dphi=np.dot(np.linalg.inv(J),f_1)
phi_23=dphi[0]+phi_23
phi_34=dphi[1]+phi_34
if dphi[0]<0.01 and dphi[1]<0.01:
break
winkel1.append(phi_12)
winkel2.append(phi_23)
phi_12+=0.01
plt.plot(winkel1,winkel2)
plt.show()
Vossi