miércoles, 12 de enero de 2011

Baseball Micky mouse cvs

Here, we can put our code on and modify it real time.

6 comentarios:

  1. function KnuckleballTrajectory(initialVelocity,spin)
    %Problem 2.17 Jaasiel Rodriguez and Karl Decker
    %Euler's Method Analysis of Knuckleball Trajectory

    initialOrientation = GetInitialOrientation();
    initialVelocity = GetInitialVelocity();

    ResponderEliminar
  2. function [initialOrientation] = GetInitialOrientation()
    %UNTITLED2 Summary of this function goes here
    % Detailed explanation goes here

    stitchPosition = '0';
    while ((stitchPosition ~= 'right') && (stitchPosition ~= 'left') && (stitchPosition ~= 'front'))
    stitchPosition = input('Please input whether the stitch starts on "right", "left", or somewhere on "front" of ball: ');
    end

    if(stitchPosition == 'right')
    initialOrientation = Pi/2;
    elseif(stitchPosition == 'left')
    initialOrientation = -Pi/2;
    elseif(stitchPosition == 'front')
    initialOrientation = rand()*pi - (pi/2);
    else
    x = 'ERROR IN FUNCITON GET INITIAL ORIENTATION';
    end
    end

    ResponderEliminar
  3. function BallPosition(vyi,vxi,vzi,AngleOrientationBall,AngularVelZaxis)

    %Specify initial conditions
    i=1
    vy(i)=vyi;
    vx(i)=vxi;
    vz(i)=vzi;
    x(i)=0;
    y(i)=0;
    z(i)=1.83; %Specify heights of the pitcher height
    dt=.001
    AngleOrientationBall(i) = 0
    gravity=9.8
    t(i)=0
    while z(i)>0
    t(i+1)=t(i)*i*dt;
    AngleOrientationBall(i+1) = AngleOrientationBall(i) + dt*AngularVelZaxis; %Gives the angle of the ball at a particulare point with respect to its center pointing in parallel with the z axis.

    AccelerationXaxis(i) = gravity * .5 * (sin(4*(AngleOrientationBall(i)))+.25*sin(8*(AngleOrientationBall(i)))+.08*sin(12*(AngleOrientationBall(i)))+.025*sin(16*(AngleOrientationBall(i)))+); % This very important term gives us the acceleration along the plane of the ground with respect to the y axis.



    vx(i+1) = vx(i)+ AccelerationXaxis(i) * dt; %velocity in plane parallel to ground (lateral velocities).
    vy(i+1) = vy(i); %velocity
    vz(i+1) = vz(i) - gravity * dt; %velocity

    x(i+1) = x(i) + vx(i) * dt ; %position in plane parallel to ground (lateral velocities).
    y(i+1) = y(i) + vy(i) * dt;
    z(i+1) = z(i) + vz(i) * dt;
    i=i+1'
    end

    plot(y,x)
    figure
    plot(t,y)
    figure
    plot(t,x)
    figure
    plot3(x,y,z)

    ResponderEliminar
  4. function BallPosition(vyi,vxi,vzi,AngleOrientationBall,AngularVelZaxis)

    %Specify initial conditions
    i=1
    vy(i)=vyi;
    vx(i)=vxi;
    vz(i)=vzi;
    x(i)=0;
    y(i)=0;
    z(i)=1.83; %Specifies height of the pitcher
    dt=.001
    gravity=9.8
    t(i)=0
    while z(i)>0
    t(i+1)=t(i)+dt;
    AngleOrientationBall(i+1) = AngleOrientationBall(i) + dt*AngularVelZaxis; %Gives the angle of the ball at a particulare point with respect to its center pointing in parallel with the z axis.

    AccelerationXaxis(i) = gravity * .5 * (sin(4*(AngleOrientationBall(i)))+.25*sin(8*(AngleOrientationBall(i)))+.08*sin(12*(AngleOrientationBall(i)))+.025*sin(16*(AngleOrientationBall(i)))); % This very important term gives us the acceleration along the plane of the ground with respect to the y axis.



    vx(i+1) = vx(i)+AccelerationXaxis(i)*dt; %velocity in plane parallel to ground (lateral velocities).
    vy(i+1) = vy(i); %velocity
    vz(i+1) = vz(i) - gravity * dt; %velocity

    x(i+1) = x(i) + vx(i) * dt ; %position in plane parallel to ground (lateral velocities).
    y(i+1) = y(i) + vy(i) * dt;
    z(i+1) = z(i) + vz(i) * dt;
    i=i+1;
    end

    plot(y,x,'Color','Red')
    xlabel('lateral displacement', 'FontName','Palatino Linotype','FontSize',12)
    ylabel('straight line to home base', 'FontName','Palatino Linotype','FontSize',12)


    figure
    plot3(x,y,z,'Color','Red')
    xlabel('lateral displacement', 'FontName','Palatino Linotype','FontSize',12)
    ylabel('straight line to home base', 'FontName','Palatino Linotype','FontSize',12)
    zlabel('height from ground', 'FontName','Palatino Linotype','FontSize',12)

    figure
    plot(y,x,'Color','Red')
    xlabel('lateral displacement', 'FontName','Palatino Linotype','FontSize',12)
    ylabel('straight line to home base', 'FontName','Palatino Linotype','FontSize',12)
    set(gca,'DataAspectRatio',[1 1 1]) %This gives us an accurate view of the displacement proportions.


    end

    ResponderEliminar
  5. function [v,Nv] = Maxwell_Boltzmann_Speed_Dist(ParticleMolarMass,Temperature,VelocityMin,VelocityMax,NumberParticles,Accuracy)

    #This little function generates vectors that have the values for velocities of marticles and there corresponding probability of being found in a system. I use a simple loop method. Mass

    AvogadrosNo = 6.02214179*10^23

    kB= 1.3806503 * 10^-23;

    ParticleMass = ParticleMolarMass/AvogadrosNo

    #We calculate the time step:
    dv=Accuracy

    #This calculates the size of the loops used to calculate the particular vectors.
    iMax=round((VelocityMax-VelocityMin)/Accuracy);

    #We allocate the space for the vectors:

    v=zeros(1,iMax);
    Nv=zeros(1,iMax);
    i=1

    #This gives the starting value of the velocity for the velocity column vector and it rounds it up or down to an integer.
    v(i)=VelocityMin;

    #Now, the simple loop. It should do a quick and clever job:

    for i=1:iMax

    #First, we calculate the vector velocities for a particular indice number.
    if (i<iMax)
    v(i+1)=v(i)+dv;

    endif

    #Next, I tell octave to calculate the actual values of N_v

    Nv(i)=4*pi*NumberParticles*((ParticleMass/(2*pi*kB*Temperature))^3/2)*v(i)^2*exp(-(ParticleMass*(v(i)^2))/(2*kB*Temperature));

    end

    plot(v,Nv)
    HANDLE = gca
    set( HANDLE, 'Color', [0,0.1,0.2] )


    end

    [v,N_v]=Maxwell_Boltzmann_Speed_Dist(2.0158,300,0,200,100000000,.1)

    ResponderEliminar
  6. function [v,T,Nv] = Maxwell_Boltzmann_Speed_Dist(ParticleMolarMass,TemperatureMin,TemperatureMax,VelocityMin,VelocityMax,NumberParticles,AccuracyVel,AccuracyTemp)

    #This little function generates vectors that have the values for velocities of marticles and there corresponding probability of being found in a system. I use a simple loop method. Mass

    AvogadrosNo = 6.02214179*10^23

    kB= 1.3806503 * 10^-23;

    ParticleMass = ParticleMolarMass/AvogadrosNo

    #We calculate the time step:
    dv=AccuracyVel

    #This calculates the size of the loops used to calculate the particular vectors.
    iMax=round((VelocityMax-VelocityMin)/AccuracyVel);

    #We allocate the space for the vectors:

    v=zeros(1,iMax);
    Nv=zeros(1,iMax);
    i=1

    #This gives the starting value of the velocity for the velocity column vector and it rounds it up or down to an integer.
    v(i)=VelocityMin;

    #Now, the simple loop. It should do a quick and clever job:
    if (TemperatureMin==TemperatureMax)

    Temperature=TemperatureMin;

    for i=1:iMax

    #First, we calculate the vector velocities for a particular indice number.

    if (i<iMax)

    v(i+1)=v(i)+dv;

    endif

    #Next, I tell octave to calculate the actual values of N_v

    Nv(i)=4*pi*NumberParticles*((ParticleMass/(2*pi*kB*Temperature))^3/2)*v(i)^2*exp(-(ParticleMass*(v(i)^2))/(2*kB*Temperature));

    end

    else

    dT=AccuracyTemp

    tMax=round((TemperatureMax-TemperatureMin)/AccuracyTemp)

    t=1

    T(t)=TemperatureMin

    for t=1:tMax

    if (t<tMax)

    T(t+1)=T(t)+dT;

    endif

    for i=1:iMax

    #First, we calculate the vector velocities for a particular indice number.

    if (i<iMax)

    v(i+1)=v(i)+dv;

    endif

    #Next, I tell octave to calculate the actual values of N_v

    Nv(t,i)=4*pi*NumberParticles*((ParticleMass/(2*pi*kB*T(t)))^3/2)*v(i)^2*exp(-(ParticleMass*(v(i)^2))/(2*kB*T(t)));

    end

    end

    end



    end

    ResponderEliminar