2011-11-07 21 views
8

से अलग-अलग उत्तरों मैं पाइपैब में ऑक्टेट में बनाए गए कोड को पोर्ट कर रहा हूं। पोर्टेड समीकरणों में से एक octave में करता है की तुलना में अजगर में नाटकीय रूप से अलग परिणाम देता है।समान समीकरण, पिलैब और ऑक्टेव

व्याख्या करने का सबसे अच्छा तरीका एक ही समीकरण से ऑक्टेट और पिलैब द्वारा उत्पन्न भूखंडों को दिखाना है।

यहां ऑक्टेट में मूल समीकरण का सरलीकृत स्निपेट है। यह छोटी परीक्षण स्क्रिप्ट में, शून्य में आयोजित फ़ाई के साथ समारोह का परिणाम ~ (-pi, अनुकरणीय) से दर्शाया गया है:

clear 
clc 
close all 

L1 = 4.25; % left servo arm length 
L2 = 5.75; % left linkage length 
L3 = 5.75; % right linkage length 
L4 = 4.25; % right servo arm length 
L5 = 11/2; % distance from origin to left servo 
L6 = 11/2; % distance from origin to right servo 

theta_array = [-pi+0.1:0.01:pi-0.1]; 
phi = 0/180*pi; 

for i = 1 : length(theta_array) 

theta = theta_array(i); 

A(i) = -L3*(-((2*cos(theta)*L1*(sin(phi)*L4-sin(theta)*L1)-2*sin(theta)*L1*(L6+L5-cos(phi)*L4-cos(theta)*L1))/(2*L3*sqrt((L6+L5-cos(phi)*L4-cos(theta)*L1)^2+(sin(phi)*L4-sin(theta)*L1)^2))-((2*sin(theta)*L1*(L6+L5-cos(phi)*L4-cos(theta)*L1)-2*cos(theta)*L1*(sin(phi)*L4-sin(theta)*L1))*(-(L6+L5-cos(phi)*L4-cos(theta)*L1)^2-(sin(phi)*L4-sin(theta)*L1)^2-L3^2+L2^2))/(4*L3*((L6+L5-cos(phi)*L4-cos(theta)*L1)^2+(sin(phi)*L4-sin(theta)*L1)^2)^(3/2)))/sqrt(1-(-(L6+L5-cos(phi)*L4-cos(theta)*L1)^2-(sin(phi)*L4-sin(theta)*L1)^2-L3^2+L2^2)^2/(4*L3^2*((L6+L5-cos(phi)*L4-cos(theta)*L1)^2+(sin(phi)*L4-sin(theta)*L1)^2)))-((cos(theta)*L1)/sqrt((L6+L5-cos(phi)*L4-cos(theta)*L1)^2+(sin(phi)*L4-sin(theta)*L1)^2)-((sin(theta)*L1-sin(phi)*L4)*(2*sin(theta)*L1*(L6+L5-cos(phi)*L4-cos(theta)*L1)-2*cos(theta)*L1*(sin(phi)*L4-sin(theta)*L1)))/(2*((L6+L5-cos(phi)*L4-cos(theta)*L1)^2+(sin(phi)*L4-sin(theta)*L1)^2)^(3/2)))/sqrt(1-(sin(theta)*L1-sin(phi)*L4)^2/((L6+L5-cos(phi)*L4-cos(theta)*L1)^2+(sin(phi)*L4-sin(theta)*L1)^2)))*sin(acos((-(L6+L5-cos(phi)*L4-cos(theta)*L1)^2-(sin(phi)*L4-sin(theta)*L1)^2-L3^2+L2^2)/(2*L3*sqrt((L6+L5-cos(phi)*L4-cos(theta)*L1)^2+(sin(phi)*L4-sin(theta)*L1)^2)))-asin((sin(theta)*L1-sin(phi)*L4)/sqrt((L6+L5-cos(phi)*L4-cos(theta)*L1)^2+(sin(phi)*L4-sin(theta)*L1)^2))); 

end 

plot(theta_array,A) 

जिसके परिणामस्वरूप सप्तक साजिश इस तरह दिखता है:

Octave result

उसी समीकरण की प्रतिलिपि बनाई गई थी और इसे '**' के साथ '^' के साथ बदलकर '^' के साथ पाइथन में चिपकाया गया था, 'एकोस' 'आर्ककोस' के साथ बदल दिया गया था, और 'asin' को 'arcsin' के साथ बदल दिया गया था। थीटा की एक ही श्रेणी शून्य में आयोजित फ़ाई के साथ साजिश रची गई थी:

from pylab import * 

# physical setup 
L1 = 4.25; # left servo arm length 
L2 = 5.75; # left linkage length 
L3 = 5.75; # right linkage length 
L4 = 4.25; # right servo arm length 
L5 = 11.0/2.0; # distance from origin to left servo 
L6 = 11.0/2.0; # distance from origin to right servo 

theta = arange(-pi+0.1,pi-0.1,0.01); 
phi = 0/180.0*pi 

def func(theta,phi): 

A = -L3*(-((2*cos(theta)*L1*(sin(phi)*L4-sin(theta)*L1)-2*sin(theta)*L1*(L6+L5-cos(phi)*L4-cos(theta)*L1))/(2*L3*sqrt((L6+L5-cos(phi)*L4-cos(theta)*L1)**2+(sin(phi)*L4-sin(theta)*L1)**2))-((2*sin(theta)*L1*(L6+L5-cos(phi)*L4-cos(theta)*L1)-2*cos(theta)*L1*(sin(phi)*L4-sin(theta)*L1))*(-(L6+L5-cos(phi)*L4-cos(theta)*L1)**2-(sin(phi)*L4-sin(theta)*L1)**2-L3**2+L2**2))/(4*L3*((L6+L5-cos(phi)*L4-cos(theta)*L1)**2+(sin(phi)*L4-sin(theta)*L1)**2)**(3/2)))/sqrt(1-(-(L6+L5-cos(phi)*L4-cos(theta)*L1)**2-(sin(phi)*L4-sin(theta)*L1)**2-L3**2+L2**2)**2/(4*L3**2*((L6+L5-cos(phi)*L4-cos(theta)*L1)**2+(sin(phi)*L4-sin(theta)*L1)**2)))-((cos(theta)*L1)/sqrt((L6+L5-cos(phi)*L4-cos(theta)*L1)**2+(sin((phi)*L4-sin(theta)*L1)**2)-((sin(theta)*L1-sin(phi)*L4)*(2*sin(theta)*L1*(L6+L5-cos(phi)*L4-cos(theta)*L1)-2*cos(theta)*L1*(sin(phi)*L4-sin(theta)*L1)))/(2*((L6+L5-cos(phi)*L4-cos(theta)*L1)**2+(sin(phi)*L4-sin(theta)*L1)**2)**(3/2)))/sqrt(1-(sin(theta)*L1-sin(phi)*L4)**2/((L6+L5-cos(phi)*L4-cos(theta)*L1)**2+(sin(phi)*L4-sin(theta)*L1)**2)))*sin(arccos((-(L6+L5-cos(phi)*L4-cos(theta)*L1)**2-(sin(phi)*L4-sin(theta)*L1)**2-L3**2+L2**2)/(2*L3*sqrt((L6+L5-cos(phi)*L4-cos(theta)*L1)**2+(sin(phi)*L4-sin(theta)*L1)**2)))-arcsin((sin(theta)*L1-sin(phi)*L4)/sqrt((L6+L5-cos(phi)*L4-cos(theta)*L1)**2+(sin(phi)*L4-sin(theta)*L1)**2))) 

return A 

f = figure(); 
a = f.add_subplot(111); 

a.plot(theta,func(theta,phi)) 

ginput(1, timeout=-1); # wait for user to click so we dont lose the plot 

पायथन के परिणाम इस प्रकार है: Python result

मैं नहीं कर सकते निर्धारित क्या मतभेद उत्पन्न कर रहा है, कोई भी विचार?

+1

वे कार्य मूल कार्य के _simplified_ संस्करण हैं? वाह। किसी भी मौके पर आप एक ही समय में दोनों टुकड़ों से समान हिस्सों को खटखटा सकते हैं और अभी भी कुछ छोटे खोजने की कोशिश कर सकते हैं? :) – sarnold

+0

फ़ंक्शन की जटिलता को देखते हुए, क्या यह विभिन्न फ़्लोटिंग-पॉइंट परिशुद्धता और/या गोल करने वाली त्रुटियों का मुद्दा हो सकता है? क्या आपने कारण को कम करने के लिए फ़ंक्शन के छोटे हिस्सों को साजिश करने का प्रयास किया है? –

+0

यह इस अर्थ में सरलीकृत है कि स्टैक ओवरफ्लो गुरु के लिए समस्या को सरल बनाने के लिए सभी अपरिपक्व कोड निकाले गए थे। –

उत्तर

12

फर्श विभाजन से उत्पन्न त्रुटियों को खत्म करने के लिए from __future__ import division आज़माएं।

+0

हज़ह में! धन्यवाद! ऐसा लगता है कि इसे ठीक किया गया है। क्या कोई अन्य गणित गठिया है जिसके लिए मुझे देखना चाहिए? –

+0

@Inverse_Jacobian: यदि यह उत्तर आपकी समस्या हल करता है, तो आपको इसे स्वीकार करना चाहिए (इसके द्वारा चेक-मार्क पर क्लिक करें)। –

संबंधित मुद्दे