How to implement cross products and matricies

9 vues (au cours des 30 derniers jours)
Samsquanch
Samsquanch le 8 Oct 2017
Modifié(e) : Samsquanch le 8 Oct 2017
Hey just sort of new to this whole thing. I have a simple crank slider and I need to find velocity B in regards to velocity A would be vB=Va+omegaAB x rB/A my question is do I have to split the rB/A into its vector I,J, and K components? and how would I implement that as a prompt? I have a previous code that just relates the system in terms of position and I would just use the following as an input
prompt = 'Enter a value? ';
x = input(prompt)
My question is do I need to input all my values as matrices in order to cross product them?
I have attached my code that I will be modifying there is a function and a program. I put the entirety of the code in quotation marks "" as it has end statements in it as was hard to format with the HTML code to upload into the site.
if true
"function [Results] = SliderCrankAcc2(rAB,rBC,thetaAB, omegaAB, alphaAB);
rABx=rAB*cos(thetaAB*pi/180);
rABy=rAB*sin(thetaAB*pi/180);
rABz=0;
if(abs(rABx) <1e-10)
rABx=0;
end
if (abs(rABy) <1e-10)
rABy=0;
end
rBAVector = [rABx,rABy,rABz];
if(thetaAB*pi/180==0| thetaAB*pi/180==pi)
thetaBC=0;
rCBx=rBC;
rCBy=0;
rCBz=0;
elseif(thetaAB*pi/180>0 & thetaAB*pi/180<pi)
thetaBC=2*pi-asin(rAB*sin(theataAB*pi/180)/rBC);
rCBx=rBC*cos(thetaBC);
rCBy=rBC*sin(thetaBC);
rCBz0;
elseif(thetaAB*pi/180>pi & thetaAB*pi/180<=2*pi)
rCBx=rBC*cos(thetaBC);
rCBy=rBC*sin(thetaBC);
rCBz=0;
end
if (abs(rCBx) <1e-10)
rCBx=0;
end
if(abs(rCBy)<1e-10)
rCBy=0;
endrCBVector=[rCBx,rCBy,rCBz];
rCAVector=[rABx+rCBx,rABy+rABx,rABz+rCBz];
rAC=norm(rCAVector);
thetaBC=thetaBC*190/pi;
Results=[rAC,thetaBC];
return;"
% code
end
  1 commentaire
Samsquanch
Samsquanch le 8 Oct 2017
Modifié(e) : Samsquanch le 8 Oct 2017
if true
% code
close all;
clear all;
clc;
angleIncrement = 10;
numOfLoops = 360/angleIncrement;
thetaABVector = [angleIncrement:angleIncrement:360];
prompt = 'Please enter a whole number value for rAB ';
rAB = input(prompt)
prompt = 'Please enter a whole number value for rBC';
rBC = input(prompt)
prompt ='Please enter a whole number value for thetaAB';
thetaAB= input(prompt)
prompt= 'Please enter a whole number value for omegaAB';
omegaAB= input(prompt);
prompt= 'Please enter a whole number value for alphaAB';
alphaAB= input(prompt);
for i=1:numOfLoops
bothResults = SliderCrankAcc2(rAB,rBC,thetaAB, omegaAB, alphaAB);
rAC(i) = bothResults(1);
thetaBC(i) = bothResults(2);
thetaAB = thetaAB+angleIncrement;
end
subplot(2,1,1) %parameters of the plot graph
plot(thetaABVector,thetaBC,'Linewidth',3); %plot thetaABVector, thetaBC with a linewidth of 3 making is bolder and fatter.
xlabel('\theta_{AB} [degrees]'); %lable the x-axis of the first plot to be thetaAB degrees
ylabel('\theta_{BC} [degrees]'); %lable the y-axis of the first plot to be thetaBC degrees
xlim([0 360]); %limits in the x-axis between 0 and 360
ylim([300 400]); %limits in the y-axis to be between 300 and 400
grid on; %turn the grid on to see lines
subplot(2,1,2) %create a two 2x1 graphs
plot(thetaABVector,rAC,'r'); %plot thetaABVector in the second graph in terms of position
xlabel('\theta_{AB} [degrees]'); %lable the x-axis in terms of degrees and lable it theta AB degrees
ylabel('r_{AC} [inches]'); %lable y-axis in terms of postion and call it rAC inches
xlim([0 360]); %set a limit for x-variables to be between 0 and 360
grid on; %Turn gridlines on for the second plot
end

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by