MATLAB Practice - Exercises
MATLAB Practice - Exercises
•
Introduction to MATLAB – Step by Step Exercise
6. Create vectors:
• vector_1 = [1 2 3 4 5 6 7 8 9 10]
• vector_2 = [12 13 14 15 16 17 8767826264]
for i = 1:how_may_dates
disp(['The date is: ' num2str(dates(i))]);
end
Introduction to MATLAB – Step by Step Exercise
28. Create a "if" to check if a year is before, equal or
after year 1800
year = 1750;
if year < 1800
disp('Year is before 1800');
elseif year == 1800
disp('Year is 1800');
else
disp('Year is above 1800');
end
Introduction to MATLAB – Step by Step Exercise
29. Incorporate and modify the "if" inside your "for", to
check if a date is before, after or equal 1814
for i = 1:how_may_dates
disp(['The date is: ' num2str(dates(i))]);
if dates(i) < 1814
disp('Before 1814');
elseif dates(i) == 1814
disp('It is 1814!');
else
disp('After 1814');
end
end
Introduction to MATLAB – Step by Step Exercise
29. Incorporate and modify the "if" inside your "for", to
check if a date is before, after or equal 1814
for i = 1:how_may_dates
disp(['The date is: ' num2str(dates(i))]);
if dates(i) < 1814
disp('Before 1814');
elseif dates(i) == 1814
disp('It is 1814!');
else
disp('After 1814');
end
end
Introduction to MATLAB – Step by Step Exercise
30. Adapt your code from 29 to solve the example from
last week:
sum([1 2])
length([1 2])
times([2],[2])
Introduction to MATLAB – Step by Step Exercise
>> a = [1 2];
>> b = [3 4];
>> c = [5;6];
>> d = [a;b];
>> e = [d c];
>> f = [[e e];[a b a]];
Introduction to MATLAB – Step by Step Exercise
coeff = polyfit(x,y,1);
y_fit = polyval(coeff,x);
t=0:pi/50:10*pi;
plot3(sin(t),cos(t),t, 'r.'),grid
on,xlabel('x'),
ylabel('y'),zlabel('z'),
title('3D helix')
Introduction to MATLAB – Step by Step Exercise
Elliptic torus
where r1 = r2 = 0.5, t = 1.5, 0 < u < 10π and 0 < v < 10π
Introduction to MATLAB – Step by Step Exercise
x = 0:pi/100:pi;
y = sin(x);
trapz(y,x) % returns 1.9338
plot (x,y,'k-*')
σ = PL*6/h3
Consider:
load_vector = 100:100:1000!
section_h_vector = 10:10:100!
Introduction to MATLAB – Step by Step Exercise