Created
September 27, 2013 18:12
-
-
Save senhorinha/6732720 to your computer and use it in GitHub Desktop.
Cálculo Numérico para Cap 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# f(x) = tg(x) - 1 = 0 | |
# raiz está entre o intervalo [0,1] | |
# Método da biscessão | |
function x = biscessao(a,b,erroMaximo) | |
erro = 1; | |
count = 1; | |
while(erro > erroMaximo & count < 50) | |
x1 = x; | |
x = 0.5*(a+b) | |
if(f(a)*f(x) < 0) | |
a = a; % a não muda | |
b = x; | |
else | |
a = x; | |
b = b; % b não muda | |
end | |
count++; | |
printf("\nx = %0.30f\n",x); | |
printf("\na = %0.30f\n",a); | |
printf("\nb = %0.30f\n",b); | |
#Alguns tipos de erros | |
# erro = abs(b-a); # Erro para segurança, ou seja, o erro da raiz real é menor ainda. | |
# erro = abs(x - x1) | |
# erro = abs(f(x)) | |
erro = abs((x-x1)/x) + abs(f(x)) | |
end; | |
end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear | |
format long | |
a = 0; | |
b = 1; | |
x = a; | |
erroMaximo = 1.e-6; | |
x = biscessao(a,b,erroMaximo); | |
x = falsaPosicao(a,b,erroMaximo); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function y = f(x) | |
y = x.*tan(x) - 1; | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# f(x) = tg(x) - 1 = 0 | |
# raiz está entre o intervalo [0,1] | |
# Método da Falsa Posicao | |
function x = falsaPosicao(a,b,erroMaximo) | |
a = 0; | |
b = 1; | |
erro = 1; | |
count = 1; | |
x = a; | |
while(erro > erroMaximo & count < 50) | |
x1 = x; | |
x = (a*f(b) - b*f(a))/(f(b)-f(a)); | |
if(f(a)*f(x) < 0) | |
a = a; % a não muda | |
b = x; | |
else | |
a = x; | |
b = b; % b não muda | |
end | |
count++; | |
printf("\nx = %0.30f\n",x); | |
printf("\na = %0.30f\n",a); | |
printf("\nb = %0.30f\n",b); | |
#Alguns tipos de erros | |
# erro = abs(b-a); # Erro para segurança, ou seja, o erro da raiz real é menor ainda. | |
# erro = abs(x - x1) | |
# erro = abs(f(x)) | |
erro = abs((x-x1)/x) + abs(f(x)) | |
end; | |
end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# f(x) = tg(x) - 1 = 0 | |
# raiz está entre o intervalo [0,1] | |
# Método da Iteração Linear | |
function x = falsaPosicao(a,b,erroMaximo) | |
a = 0; | |
b = 1; | |
erro = 1; | |
count = 1; | |
x = a; | |
while(erro > erroMaximo & count < 50) | |
x1 = x; | |
x = (a*f(b) - b*f(a))/(f(b)-f(a)); | |
if(f(a)*f(x) < 0) | |
a = a; % a não muda | |
b = x; | |
else | |
a = x; | |
b = b; % b não muda | |
end | |
count++; | |
printf("\nx = %0.30f\n",x); | |
printf("\na = %0.30f\n",a); | |
printf("\nb = %0.30f\n",b); | |
#Alguns tipos de erros | |
# erro = abs(b-a); # Erro para segurança, ou seja, o erro da raiz real é menor ainda. | |
# erro = abs(x - x1) | |
# erro = abs(f(x)) | |
erro = abs((x-x1)/x) + abs(f(x)) | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment