So I'm a bit of a noob with matlab and I'm not very efficient with my code writing, below is one of my scripts that gets the job done however it just seems…long and not very efficient at all which is an issue because I'll have multiple scripts that will follow this bad habit until a new method comes forward, can anyway help me condense this code?
%constants
ConrodLength=0.1375; %m
Stroke=0.082; %mThrow=0.041; %mPistonMass=0.28866; %Kg
CrankAngle=(-360:1:359)'; %Degrees
CrankAngleRad=deg2rad(CrankAngle); %Radians
%Angular velocity
w=[104.7198;130.8997;157.0796;183.2596;209.4395;235.6194;261.7994;314.1593;366.5191;418.879;471.2389;523.5988;575.9587;575.9587;628.3185;680.6784];%Inertia
for i=CrankAngleRad acc1=Throw*(w(1)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(1)^2)*cos(2*i); acct=acc1+acc2; Inertia1000=PistonMass*acct; figure subplot(1,1,1) plot(CrankAngle,Inertia1000) title('Inertia/Crank Angle') xlabel('Crank Angle (degrees)') ylabel('Inertia (Kg rad/s^2)') hold onendfor i=CrankAngleRad acc1=Throw*(w(2)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(2)^2)*cos(2*i); acct=acc1+acc2; Inertia1250=PistonMass*acct; plot(CrankAngle,Inertia1250) hold onendfor i=CrankAngleRad acc1=Throw*(w(3)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(3)^2)*cos(2*i); acct=acc1+acc2; Inertia1500=PistonMass*acct; plot(CrankAngle,Inertia1500) hold onendfor i=CrankAngleRad acc1=Throw*(w(4)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(4)^2)*cos(2*i); acct=acc1+acc2; Inertia1750=PistonMass*acct; plot(CrankAngle,Inertia1750) hold onendfor i=CrankAngleRad acc1=Throw*(w(5)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(5)^2)*cos(2*i); acct=acc1+acc2; Inertia2000=PistonMass*acct; plot(CrankAngle,Inertia2000) hold onendfor i=CrankAngleRad acc1=Throw*(w(6)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(6)^2)*cos(2*i); acct=acc1+acc2; Inertia2250=PistonMass*acct; plot(CrankAngle,Inertia2250) hold onendfor i=CrankAngleRad acc1=Throw*(w(7)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(7)^2)*cos(2*i); acct=acc1+acc2; Inertia2500=PistonMass*acct; plot(CrankAngle,Inertia2500) hold onendfor i=CrankAngleRad acc1=Throw*(w(8)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(8)^2)*cos(2*i); acct=acc1+acc2; Inertia3000=PistonMass*acct; plot(CrankAngle,Inertia3000) hold onendfor i=CrankAngleRad acc1=Throw*(w(9)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(9)^2)*cos(2*i); acct=acc1+acc2; Inertia3500=PistonMass*acct; plot(CrankAngle,Inertia3500) hold onendfor i=CrankAngleRad acc1=Throw*(w(10)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(10)^2)*cos(2*i); acct=acc1+acc2; Inertia4000=PistonMass*acct; plot(CrankAngle,Inertia4000) hold onendfor i=CrankAngleRad acc1=Throw*(w(11)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(11)^2)*cos(2*i); acct=acc1+acc2; Inertia4500=PistonMass*acct; plot(CrankAngle,Inertia4500) hold onendfor i=CrankAngleRad acc1=Throw*(w(12)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(12)^2)*cos(2*i); acct=acc1+acc2; Inertia5000=PistonMass*acct; plot(CrankAngle,Inertia5000) hold onendfor i=CrankAngleRad acc1=Throw*(w(13)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(13)^2)*cos(2*i); acct=acc1+acc2; Inertia5500=PistonMass*acct; plot(CrankAngle,Inertia5500) hold onendfor i=CrankAngleRad acc1=Throw*(w(14)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(14)^2)*cos(2*i); acct=acc1+acc2; Inertia6000=PistonMass*acct; plot(CrankAngle,Inertia6000) hold onendfor i=CrankAngleRad acc1=Throw*(w(15)^2)*cos(i); acc2=(Throw/ConrodLength)*Throw*(w(15)^2)*cos(2*i); acct=acc1+acc2; Inertia6500=PistonMass*acct; plot(CrankAngle,Inertia6500) hold onendhold off
Best Answer