Академический Документы
Профессиональный Документы
Культура Документы
SADA ( , max);
( ).
PARE.
% no MATLAB
// no SCILAB.
Comando clear:
Limpa a memria.
Operao Smbolo
Igualdade ==
Desigualdade ~=
Maior ou igual >=
Menor ou igual <=
deff([y]=f(x), funo)
EXEMPLO:
EXEMPLO:
fplot2d (x,f)
xlabel (x);
ylabel (y).
>>mtlb_
& E lgico
| OU lgico
~ NO lgico
Exemplo:
>> if <condio>
>> <comandos>
>> end
Funo: f
Preciso: tol
A cada iterao: x
SADA (x); ( ).
PARE.
Passo 5: Faa i = i + 1.
a = input(limite inferior:');
b = input(limite superior:');
tol = input(preciso');
nmax = input(nmero mximo de iteraes);
function f = f(x)
f = x.^3-9*x+3
endfunction
Aula 10 MATLAB - Zeros de funes
Clculo Numrico 36/47
Implementao
if (f(a)*f(b)>0) then
disp Este intervalo no contm raiz
else
i = 1;
while (i < max)
x = (a+b)/2;
abs(f(x)<
if ( tol
f(x) == 0 | abs(b
| abs(b a)
a) < tol)
< tol )
printf('A raiz : %1.8f\n', x);
printf('O nmero de iteraes foi:
%i', i);
break
end Aula 10 MATLAB - Zeros de funes
Clculo Numrico 37/47
Implementao
i = i + 1;
(f(x)*f(b)
if (f(x)*f(a) < ==
sign((f(x))> 0) sign(f(a)))
then then
a = x;
else
b = x;
end
end
Passo 1: Faa i = 0;
Passo 2: Enquanto i nmax , execute os passos 3 a 6.
Passo 3: Faa x = x0 f (x0) / f (x0); (Calcula xi)
Passo 4: Se |x x0| < tol, ento:
SADA (x); (Procedimento concludo com sucesso).
PARE.
x0 = input(aproximao inicial:)
tol = input(preciso:)
nmax = input (nmero mximo de iteraes:)
function f = f(x)
f = x.^3-9*x+3
endfunction
i = 0;