Advertisement
battlecake

Untitled

Jan 14th, 2023
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.97 KB | None | 0 0
  1. function [kreuzproduktx]= Kreuzprodukt(a,b)
  2.     if length(a) == 3 then
  3.    
  4.         kreuzproduktx(1) = (a(2)*b(3) - a(3)*b(2))
  5.         kreuzproduktx(2) = (a(3)*b(1) - a(1)*b(3))
  6.         kreuzproduktx(3) = (a(1)*b(2) - a(2)*b(1))
  7.     else
  8.         kreuzproduktx = (a(1)*b(2) - a(2)*b(1))
  9.     end
  10. endfunction
  11.  
  12. function [betragx]= Vektorbetrag(a)
  13.     if  length(a) == 3 then
  14.         betragx=(a(1)^2+a(2)^2+a(3)^2)^0.5
  15.     else
  16.         betragx=(a(1)^2+a(2)^2)^0.5
  17.        
  18.     end
  19. endfunction
  20.  
  21. function [skalarx]=Skalarprodukt(a, b)
  22.     if length(a)==3 then
  23.         skalarx=a(1)*b(1)+a(2)*b(2)+a(3)*b(3)
  24.     else
  25.         skalarx=a(1)*b(1)+a(2)*b(2)
  26.     end
  27. endfunction
  28.  
  29. function [winkelx]=Vektorwinkel(a,b)
  30.         winkelx=acosd(Skalarprodukt(a,b)/(Vektorbetrag(a)*Vektorbetrag(b)))
  31. endfunction
  32.  
  33. noch ausstehend:
  34. Fläche von Dreieck/Parallelogram
  35. restliche Vektoren bei einem Dreieck oder Parallelogram berechnen lassen
  36. neuen Punkt berechnen
  37. Polynomdivision
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. //------------------------Vektorberechnungen---------------------------
  51. //-----------------Winkel zwischen zwei Vektoren-----------------------
  52. Vektor1=[2 -1 4]
  53. Vektor2=[-3 -2 1]
  54.  
  55. Vektora=Vektor1
  56. Vektorb=Vektor2
  57.  
  58. Vektorc=Vektorb-Vektora
  59.  
  60. Winkelab=Vektorwinkel(Vektora, Vektorb)
  61. Winkelac=Vektorwinkel(-(Vektora), Vektorc)
  62. Winkelbc=Vektorwinkel(Vektorb, Vektorc)
  63.  
  64. Flaeche=(Vektorbetrag(Kreuzprodukt(Vektora,Vektorb)))/2
  65.  
  66.  
  67.  
  68.  
  69. //------------------------Lineare Abbildung---------------------------
  70. //Winkel der Drehung
  71. alpha=60;
  72. //Verschiebung um:
  73. Vx=0;
  74. Vy=0;
  75. //Eingabe der Koordinaten Ursprungs-Matrix
  76. a=[1 1 3]
  77. start=[2 1 7]
  78. ende=a+start
  79.  
  80. OrtsMatrix=[start;ende]'
  81.  
  82. //Berechnungsmatrizen
  83. //2D
  84. dM2d=[cosd(a) -sind(a); sind(a) cosd(a)]; //Drehmatrix, Drehung um a (2D)
  85. OrthProjX=[1 0; 0 0];           //Orthogonale Projektion auf die X Achse
  86. OrthProjY=[0 0; 0 1];           //Orthogonale Projektion auf die Y Achse
  87. IdentAbb=[1 0; 0 1];            //Identische Abbildung
  88. Sx2d=[1 0; 0 -1];               //Spiegelung an der X-Achse
  89. Sy2d=[-1 0; 0 1];               //Spiegelung an der Y-Achse
  90. Sk2d=[-1 0; 0 -1];              //Spiegelung am Koordinatenurpsrung
  91. vM=[1 0 Vx; 0 1 Vy; 0 0 1];     //Verschiebungsmatrix, Verschiebung um Vx/Vy
  92.  
  93. //3D
  94. Sx3d=[1 0 0; 0 -1 0; 0 0 -1];   //Spiegelung an der x-Achse
  95. Sxy3d=[1 0 0; 0 1 0; 0 0 -1];   //Spiegelung an xy-Ebene
  96. Syz3d=[-1 0 0; 0 1 0; 0 0 1];   //Spiegelung an yz-Ebene
  97. Sxz3d=[1 0 0; 0 -1 0; 0 0 1];   //Spiegelung an xz-Ebene
  98. Sk03d=[-1 0 0; 0 -1 0; 0 0 -1]; //Spiegelung am Koordinatenursprung
  99. dMx3d=[1 0 0; 0 cosd(alpha) -sind(alpha); 0 sind(alpha) cosd(alpha)]; //Drehung um x-Achse um a
  100. dMy3d=[cosd(alpha) 0 -sind(alpha); 0 1 0; sind(alpha) 0 cosd(alpha)]; //Drehung um y-Achse um b
  101. dMz3d=[cosd(alpha) -sind(alpha) 0; sind(alpha) cosd(alpha) 0; 0 0 1]; //Drehung um z-Achse um c
  102.  
  103. //Berechnungen
  104.  
  105. A=Sxy3d*dMy3d*OrtsMatrix
  106.  
  107.  
  108. //---------------------Determinante bilden----------------------
  109. GM=[-3 -2 4; -1 0 2; -5 -1 6]
  110. det(GM)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement