SHARE
TWEET

Untitled

a guest Apr 19th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %Berechnet das Taylorpolynom zweiten Grades ein der stelle 0
  2.  
  3. % Taylor aufruf:
  4. taylor2(Y,X,E) :- tfunc(Y,X,O),s(O,E).  %Eigabeformel nimmt die Formel und den zu differenzierenden Wert an
  5.  
  6.  
  7.                             %%% Konstruiere Hauptfunktion %%%
  8.  
  9. tfunc(Y,X,G0+G1*x+G2*x^2/2) :- nulltesglied(Y,X,G0),erstesglied(Y,X,G1),zweitesglied(Y,X,G2).
  10. nulltesglied(Y,X,E) :- ein(Y,X,E).
  11. erstesglied(Y,X,E) :- ds(Y,X,A),ein(A,X,E).
  12. zweitesglied(Y,X,E) :- ds(Y,X,D0),ds(D0,X,D1),ein(D1,X,E).
  13.  
  14.  
  15.  
  16. ein(A,X,E) :- rekursivertaylorwert(A,X,O),nulltaylorwert(O,X,O1),s(O1,E). % Der nullte Taylorwert wird eingesetzt und mit dem Rest verbunden
  17.  
  18.  
  19.                             %%% Tayloerwerte werden Rekursiv gesetzt %%%
  20.  
  21. rekursivertaylorwert(F+Y,X,EW1+EW2) :- rekursivertaylorwert(F, X, E1),nulltaylorwert(E1,X,EW1),rekursivertaylorwert(Y, X, E2),nulltaylorwert(E2,X,EW2).
  22. rekursivertaylorwert(F*Y,X,EW1*EW2) :- rekursivertaylorwert(F, X, E1),nulltaylorwert(E1,X,EW1),rekursivertaylorwert(Y, X, E2),nulltaylorwert(E2,X,EW2).
  23. rekursivertaylorwert(F-Y,X,EW1-EW2) :- rekursivertaylorwert(F, X, E1),nulltaylorwert(E1,X,EW1),rekursivertaylorwert(Y, X, E2),nulltaylorwert(E2,X,EW2).
  24. rekursivertaylorwert(F/Y,X,EW1/EW2) :- rekursivertaylorwert(F, X, E1),nulltaylorwert(E1,X,EW1),rekursivertaylorwert(Y, X, E2),nulltaylorwert(E2,X,EW2).
  25. rekursivertaylorwert(X,_,X).
  26.  
  27.                             %%% Der Taylorwert wird einzeln auf null gesetzt (X=0) %%%
  28.  
  29. nulltaylorwert(sin(X+Y),X,E) :- E is sin(Y).
  30. nulltaylorwert(-sin(X+Y),X,E) :- E is -sin(Y).
  31. nulltaylorwert(cos(X+Y),X,E) :- E is cos(Y).
  32. nulltaylorwert(-cos(X+Y),X,E) :- E is -cos(Y).
  33. nulltaylorwert(sin(X),X,0).
  34. nulltaylorwert(-sin(X),X,0).
  35. nulltaylorwert(cos(X),X,1).
  36. nulltaylorwert(-cos(X),X,-1).
  37. nulltaylorwert(X^N,X,0) :- number(N).
  38. nulltaylorwert(N*X^N,X,0) :- number(N).
  39. nulltaylorwert(N^X,X,1) :- number(N).
  40. nulltaylorwert(X,X,0).
  41. nulltaylorwert(X,X,0).
  42. nulltaylorwert(X,_,X).
  43.  
  44.  
  45.  
  46.                             %%% Trigonomisch verkettete Funktionsregeln %%%
  47.  
  48. diff(sin(Y),X,IN*cos(Y)) :- X\=Y, diff(Y,X,IN).
  49. diff(cos(Y),X,IN*(-sin(Y))) :- X\=Y, diff(Y,X,IN).
  50. diff(tan(Y),X,IN*sin(Y)/cos(Y)) :- X\=Y, diff(Y,X,IN).
  51.  
  52.  
  53.                             %%% Produktregel %%%
  54.  
  55. diff(X1*X2,X,X1*Y2+X2*Y1) :- diff(X1,X,Y1),diff(X2,X,Y2),
  56.     not(number(X1)),not(number(X2)).
  57.  
  58.  
  59.                             %%% Haupt Regeln %%%
  60.  
  61. diff(X,X,1).
  62. diff(C,X,0) :- number(C), X\==C.
  63. diff(C*X,X, C) :- number(C), X\==C.
  64. diff(-F,X,-DF) :- diff(F,X,DF).
  65.  
  66.  
  67.                             %%% Potenz Regeln %%%
  68.  
  69. diff(X^N,X,N*X^Z):- Z is N-1, number(N).
  70. diff(K*X^N,X,K*N*X^Z):- Z is N-1, number(N), number(K).
  71. diff(e^X,X,e^X).
  72. diff(e^N*X,X,N*e^N*X):- number(N).
  73.  
  74.  
  75.                             %%% Verkettungsregeln für Polynome mit Potenzen%%%
  76.  
  77. diff(P^N, X, DP*(P^Z)*N) :- P\=X, Z is N-1, diff(P,X,DP).
  78.  
  79.  
  80.                             %%% Summieren und Differenzieren %%%
  81.  
  82. diff(A+B,X,DFX+DFY) :- diff(A,X,DFX),diff(B,X,DFY).
  83. diff(A-B,X,DFX-DFY) :- diff(A,X,DFX),diff(B,X,DFY).
  84.  
  85.  
  86.                             %%% Trigonometrische Funktionen %%%
  87. diff(sin(X),X,cos(X)).
  88. diff(cos(X),X,-sin(X)).
  89. diff(tan(X),X,sin(X)/cos(X)).
  90.  
  91.  
  92.                             %%% Termvereinfachung %%%
  93.  
  94. simplification0(X*X,X^2) :- not(number(X)).
  95. simplification0(1*X,X).
  96. simplification0(X*1,X).
  97. simplification0(X/1,X).
  98. simplification0(0+X,X).
  99. simplification0(X+0,X).
  100. simplification0(0*_,0).
  101. simplification0(_*0,0).
  102. simplification0(0/_,0).
  103.  
  104.  
  105.                             %%% Kürzung %%%
  106.  
  107. simplification0(N+V,X) :- number(N),number(V), X is N+V.
  108. simplification0(N*X*V,E) :- number(N),number(V), Z is N*V, simplification0(Z*X,E).
  109. simplification0(N*X/V,E) :- number(N),number(V), Z is N/V, simplification0(Z*X,E).
  110. simplification0(N*X^1,N*X) :- number(N).
  111.  
  112.  
  113.                             %%% Ende Main %%%
  114. simplification0(X,X).
  115.  
  116.  
  117.                             %%% Simplifizierung %%%
  118.  
  119. s(A+B,X) :- s(A,E1),s(B,E2),simplification0(E1+E2,X).
  120. s(A-B,X) :- s(A,E1),s(B,E2),simplification0(E1-E2,X).
  121. s(A*B,X) :- s(A,E1),s(B,E2),simplification0(E1*E2,X).
  122. s(A/B,X) :- s(A,E1),s(B,E2),simplification0(E1/E2,X).
  123. s(X,X).
  124.  
  125. % abfrage fuer ableitung
  126. ds(F,X,DF) :- diff(F,X,S),s(S,REC),simplification0(REC,DF).
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top