Uploaded by Will Bleier

Lab1 244

advertisement
%1
x=6
x = 6
y=5
y = 5
ans0=x*y
ans0 = 30
ans1=x^2+y^2
ans1 = 61
ans2=x/(3*y)
ans2 = 0.4000
%2
disp(['The number x is ' num2str(x) '.'])
The number x is 6.
disp(['The number y is ' num2str(y) '.'])
The number y is 5.
disp(['The number xy is ' num2str(ans0) '.'])
The number xy is 30.
%3
w=randi([1 100])
w = 86
if mod(w,2) == 0
disp('The number w is even')
else
disp('The number w is odd')
end
The number w is even
%4
fibonacciArray = zeros(1,20);
fibonacciArray(1) = 0;
fibonacciArray(2) = 1;
for i = 3:20
fibonacciArray(i) = fibonacciArray(i-1) + fibonacciArray(i-2);
end
disp('Fibonacci Numbers:');
1
Fibonacci Numbers:
disp(fibonacciArray);
0
1
1
2
3
%5
figure;
f = @(x) sin(x);
g = @(x) x-1;
xVals = linspace(0,3,1000);
y=f(xVals);
plot(xVals,y)
ylim([-1.5,1.5])
xlabel('x');
ylabel('y');
hold on
y=g(xVals);
plot(xVals,y)
ylim([-1.5,1.5]);
grid on
hold off
%6
figure;
f = @(t,y) t-y.^2;
xlabel('t');
2
5
8
13
21
ylabel('y');
xlim([0,5]);
ylim([-3,10]);
yticks([-3,0,5,10]);
quiver244(f,0,5,-3,10,'b')
xlim([0,5]);
ylim([-3,10]);
xlabel('t');
ylabel('y');
yticks([-3,0,5,10]);
%7
samplePlots244(f,0,5,-3,10,5,2,'r')
samplePlots244(f,0,5,-3,10,2,2,'r')
samplePlots244(f,0,5,-3,10,3,9,'r')
3
4
Download