Escolar Documentos
Profissional Documentos
Cultura Documentos
1/7
format long
phi=(1+sqrt(5))/2
10.12.%help fsolve
f = @(x) x-sqrt(1+x)
p = @(x) x^2-x-1
x2 = fsolve(f, 1)
x3 = fsolve(f, -1)
x4 = fsolve(p, 1)
x5 = fsolve(p, -1)
1.14.- % typeset math expressions
format long
pretty(solve('1/x=x-1'))
1.9
% roots
x1 = roots([1 -1 -1])
% fzero
y = tan(x)
z=x
x0=fzero(@(x) tan(x)-x, 4.4)
y0=tan(x0)
x0 = 4.493409457909064
y0 = 4.493409457909065
1.11
look for a zero near x=1:
phi=fzero(f,1)
hold on
plot(phi,0,'+')
1.13
% solve and syms
syms x
x6 = solve('x-sqrt(1+x)=0')
x7 = solve(x^2-x-1)
1.16.- r(1)=double(r(1))
% double precision floating point
2/7
s = 1.082323233710861
n=
9742
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',5)
1.25
x = -pi:.1:pi;
y = sin(x);
plot(x,y)
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})
3/7
1.29
t = -pi:pi/100:pi;
y = sin(t);
plot(t,y)
axis([-pi+0.2 pi+0.2 -1.3 1.3])
xlabel('-\pi \leq {\itt} \leq \pi')
ylabel('sin(t)')
title('Graph of the sine function')
text(1,-1/3,'{\itNote the odd symmetry.}')
clf;
t = -2*pi:pi/100:2*pi;
x0 = -abs(fzero(@(t) tan(t)-t, -4.4));
y0=tan(x0);x1=fzero(@(t) tan(t)-t, 4.4);
y1=tan(x1);f=tan(t);f(2,:)=t;
plot(t,f,0,0,'o',x0,y0,'o',x1,y1,'o');
axis([-2*pi 2*pi -10 10]);
xlabel('-2\pi \leq {\itt} \leq 2\pi');
ylabel('sin(t)');
title('Graph of the tan function');
text(1,-1/3,'{\it 3 zeros tan(t)-t.}');
t = 0:0.001:2;
% 2 secs @ 1kHz sample rate
% Start @ DC, cross 150Hz at t=1 sec
y = chirp(t,0,1,150);
spectrogram(y,256,250,256,1E3,'yaxis')
Fs = 1000;
% Sampling
frequency
T = 1/Fs;
% Sample time
L = 1000;
% Length of
signal
t = (0:L-1)*T;
% Time vector
% Sum of a 50 Hz sinusoid and a 120 Hz
sinusoid
x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
y = x + 2*randn(size(t));
% Sinusoids
plus noise
figure(1); plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random
4/7
Noise')
xlabel('time (milliseconds)')
NFFT = 2^nextpow2(L); % Next power of 2 from
length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
figure(2); plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of
y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
logarithmic chirp
5/7
1.32.-
n=24;f = zeros(n,1);
1.2. Fibonacci Numbers 9
f(1) = 1;f(2) = 2;for k = 3:n
f(k) = f(k-1) + f(k-2);
end
ans = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
1597 2584 4181 6765 10946 17711 28657 46368
75025
function f = fibnum(n)
%FIBNUM Fibonacci number.
%
FIBNUM(n) generates the n-th Fibonacci
number.
if n <= 1
f = 1;
else
f = fibnum(n-1) + fibnum(n-2);
end
% Default example
if nargin == 0
f = @(x) sqrt(1 + x);
xmin = -1;
xmax = 4;
xstart = 0;
end
% Iteration
x = xstart; y = f(x); n = 1;
while (x(n) ~= y(n)) & (n < 50) &
(max(abs(y)) < 100)
n = n+1;
x(n) = y(n-1);
y(n) = f(x(n));
end
% Plot
t = sort([xmin:(xmax-xmin)/256:xmax x]);
x = [x; x];
y = [x(1) y(1:n-1); y];
plot(t,t,'-',t,f(t),'-',x(:),y(:),'k',x(end),y(end),'ro');
axis tight
axis square
set(zoom(gcf),'ActionPostCallback','zoomer')
1.34
t = 0:0.001:1;
% 1 second @ 1kHz sample
rate
fo = 100; f1 = 25;
% Start at 100Hz, go down to
25Hz
y = chirp(t,fo,1,f1,'q',[],'concave');
spectrogram(y,hanning(256),128,256,1000,'yaxis')
6/7
1.35 contraction: f(x) = sqr(1 + x). For points xn and xn+1 near a fixed point, the function satisfies
abs(yn+1 yn) = abs(f(xn+1) - f(xn)) < *abs( xn+1 xn). This implies that after n steps:
abs(xn+1 xn) < ^n * abs(x1 - x0) . f'(x0), the value of the derivative of f(x) at the fixed point
^10? ^32? fixed point is root to x=sqrt(1+x), since ^n>abs(xn+1-xn)/abs(x1-x0) (f'(x0))^n
x=sqrt(1+x) x0=1.618033988770158
f(x)=sqrt(1+x)) f'(x)=-0.5*(1+x)^(-0.5)
(f'(x0))^10 = 7.940057378387408e-6
(f'(x0))^32 = 4.780085345013851e-17
MSWindows calculator (ver 6.1 build 7600): x=sqrt(1+x) x0=1.618033988770158,
abs(x0-sqrt(1+x0)) = 1.4001493531043385682988887303586e-11
1.36
%LOTKA Lotka-Volterra predator-prey model.
function yp = lotka(t,y)
global ALPHA BETA
yp = [y(1) - ALPHA*y(1)*y(2); -y(2) + BETA*y(1)*y(2)];
% ALPHA = BETA = 0.1 race mode
%file lotka2.m
global ALPHA BETA
ALPHA = 0.01
BETA = 0.03
[t,y] = ode23(@lotka,[0,10],[1; 1]);
plot(t,y);
% ALPHA = 1, BETA = 0.03 persecution mode
7/7