Clear Filters
Clear Filters

Plotting with If-else statement

2 views (last 30 days)
Daryl Chua
Daryl Chua on 21 Oct 2019
Matlab code
im trying to plot but cant properly show it
for i=0:0.1:o4;
if (i<=o1) & (i>=0)
y1=(((Ra/2)*i.^2+(w/6)*i.^3+c1)/(E*I))*1000000;
y2=(((Ra/6)*i.^3+(P1/6)*(i-L1).^3-(w/24)*i.^4+c1*i)/((E*I)/1000.^2));
elseif (i<=o2) & (i>=o3)
y1=(((Ra/2)*i.^2+(P1/2)*(i-L1).^2+(w/6)*i.^3-(w/6)*(i-L1-L2).^3+c1)/(E*I))*1000000;
y2=(((Ra/6)*i.^3+(P1/6)*(i-L1).^3+M/2*(i-(L1+L2)).^2-(w/24)*i.^4+c1*i)/((E*I)/1000.^2));
else (i<=o3)&(i>=o4)
y1=(((Ra/2)*i.^2+(P1/2)*(i-L1).^2+M*(i-(L1+L2))+(P2/2)*(i-L1-L2-L3).^2+(w/6)*i.^3-(w/6)*(i-L1-L2).^3+c1)/(E*I))*1000000;
y2=(((Ra/6)*i.^3+(P1/6)*(i-L1).^3+M/2*(i-(L1+L2)).^2+(P2/6)*(i-L1-L2-L3).^3-(w/24)*i.^4+(w/24)*(i-L1-L2).^4+c1*i)/((E*I)/1000.^2));
end
end
subplot(2,1,2);
plot(i,y1,'b.');
title('Plot of the slope');
subplot(2,1,1);
plot(i,y2,'r.');
title('Plot of the Beam Deflection');

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!