0% found this document useful (0 votes)
8 views3 pages

Exercise - For Statement

Uploaded by

Anis Nadhirah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Exercise - For Statement

Uploaded by

Anis Nadhirah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

%Problem Example 1

V=[5 -9 -3 0 8 0 -7 12 15];
for i=1:length(V)
if V(i)>0 && (rem(V(i),3)==0 || rem(V(i),5)==0)
V(i)=2*V(i);
elseif V(i)<0 && V(i)>-5
V(i)=V(i)^3;
end
end
V

V = 1×9
10 -9 -27 0 8 0 -7 24 30

%Problem Example 2
mat=input('Please enter the martix. \nEnclose input with[ ]\n');
[r,c]=size(mat);
for co=1:c
cosum=0;
for ro=1:r
if mat(ro,co)>=0
cosum=cosum+mat(ro,co);
end
end
fprintf('Sum of +ve no. of column %d is %.2f\n',co,cosum)
end

Sum of +ve no. of column 1 is 12.00


Sum of +ve no. of column 2 is 16.00
Sum of +ve no. of column 3 is 8.00
Sum of +ve no. of column 4 is 23.00

%Problem Example 3
q=input('Enter load intensity, q: ');
d1=input('Enter load start dist., d1: ');
d2=input('Enter load end dist., d2: ');
l=input('Enter beam span., l: ');
n=input('Enter the number of division: ');
if d1 >= 0 && d2 > d1 && d2 <= l
disp('Valid')
else
disp('Invalid. Please check data whether 0 ≤ d1 < d2 ≤ l')
end

Valid

maxbm=0;
qlen=d2-d1;qtot=qlen*q;
rb=(qtot*(d1+d2)/2)/l;

1
ra=qtot-rb;
d=l/n;
for nx=0:n
x=nx*d;
if x<=d1
bmx=ra*x;
elseif x<=d2
bmx=ra*x-q*(x-d1)^2/2;
else
bmx=rb*(l-x);
end
if bmx>maxbm
maxbm=bmx;
xmaxbm=x;
end
end
x_values(nx+1)=x;
bmx_values(nx+1)=bmx;
table(x_values',bmx_values','VariableNames',{'x','bmx'})

ans = 20×2 table


x bmx

1 0 0
2 0.4211 11.3684
3 0.8421 22.7368
4 1.2632 34.1053
5 1.6842 45.4737
6 2.1053 56.7535
7 2.5263 65.9945
8 2.9474 72.3989
9 3.3684 75.9668
10 3.7895 76.6981
11 4.2105 74.5928
12 4.6316 69.6510
13 5.0526 61.8947
14 5.4737 53.0526
15 5.8947 44.2105
16 6.3158 35.3684
17 6.7368 26.5263
18 7.1579 17.6842
19 7.5789 8.8421

2
x bmx

20 8 0

plot(x_values,bmx_values)
xlabel('x')
ylabel('bmx')
title('Bending Moment Diagram')
grid on

fprintf('Reaction at A is %.2f & at B is %.2f\n',ra,rb)

Reaction at A is 27.00 & at B is 21.00

fprintf('The max.BM is %.2f at x = %.2f\n',maxbm,xmaxbm)

The max.BM is 76.70 at x = 3.79

You might also like