Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alguns códigos em Scilab e outras sugestões #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions cap_derivacao/cap_derivacao.tex
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,35 @@ \subsection*{Exercícios resolvidos}
\end{equation}
onde $f'(x) = 2\sen(2x) - 2x$ é a derivada analítica. Tomando $h=0,01$ temos:
\begin{equation}
D_{+,0,1}f(2) = -5,302065,\quad |f'(2)-D_{+,0,1}f(2)| = 5,22\times 10^{-3}.
D_{+,0,01}f(2) = -5,302065,\quad |f'(2)-D_{+,0,1}f(2)| = 5,22\times 10^{-3}.
\end{equation}

%%%%%%%%%%%%%%%%%%%%
% Scilab
%%%%%%%%%%%%%%%%%%%%
\ifisscilab
\construirScilab
No \verb+Scilab+, podemos fazer os cálculos com o seguinte código:
\begin{verbatim}
deff('y=f(x)','y = sin(2*x)-x^2') // Definição da função
deff('y=f1(x)','y = 2*cos(2*x)-2*x') // Definição derivada analitica

x0 = 2
h = 0.1
// h = 0.1
df = (f(x0+h)-f(x0))/h // Diferenças finitas progressiva de primeira ordem

mprintf('Diferenças finitas progressiva de primeira ordem com h = %g \n',h)
mprintf('Df = %.6e \n',df)
mprintf('Erro = %.2e \n',abs(f1(2)-df))

// h = 0.01
h = 0.01
df = (f(x0+h)-f(x0))/h // Diferenças finitas progressiva de primeira ordem

mprintf('Diferenças finitas progressiva de primeira ordem com h = %g \n',h)
mprintf('Df = %.6e \n',df)
mprintf('Erro = %.2e \n',abs(f1(2)-df))
\end{verbatim}
\fi
%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%
Expand Down
76 changes: 71 additions & 5 deletions cap_integracao/cap_integracao.tex
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ \section{Somas de Riemann}
\end{equation}

\begin{ex}
A integral de $f(x) = e^{-x}\sen(x)$ no intervalo $[0,1, 0,2]$ é
A integral de $f(x) = e^{-x}\sen(x)$ no intervalo $[0,1]$ é
\begin{equation}
\int_{0}^{1} f(x)\,dx \approx 2,45837\E-1.
\int_{0}^{1} f(x)\,dx \approx 2,45837\times 10^{-1}.
\end{equation}
Usando somas de Riemann à esquerda com $10$ intervalos, obtemos
\begin{equation}
Expand All @@ -139,7 +139,35 @@ \section{Somas de Riemann}
% scilab
%%%%%%%%%%%%%%%%%%%%
\ifisscilab
\construirScilab
No \verb+Scilab+, podemos computar as somas de Riemann da seguinte forma:
\begin{verbatim}
deff('y=f(x)','y = exp(-x)*sin(x)')

a = 0
b = 1
n = 10
h = (b-a)/n
x = linspace(a,b,n+1)

S_esq = 0
S_dir = 0
S_med = 0

for i = 1:n
S_esq = S_esq + f(x(i))*h
end
mprintf('A esquerda %.5e \n',S_esq)

for i = 1:n
S_dir = S_dir + f(x(i+1))*h
end
mprintf('A esquerda %.5e \n',S_dir)

for i = 1:n
S_med = S_med + f((x(i)+x(i+1))/2)*h
end
mprintf('A esquerda %.5e \n',S_med)
\end{verbatim}
\fi
%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -344,7 +372,16 @@ \subsection{Regra do ponto médio}
% scilab
%%%%%%%%%%%%%%%%%%%%
\ifisscilab
\construirScilab
No \verb+Scilab+, computamos:
\begin{verbatim}
deff('y=f(x)','y = exp(-x)*sin(x)')

a = 0.1
b = 0.3
h = b-a

I = h*f((a+b)/2)
\end{verbatim}
\fi
%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -1750,7 +1787,36 @@ \subsection{Integrandos com singularidade do tipo $1/(x-a)^n$}
% scilab
%%%%%%%%%%%%%%%%%%%%
\ifisscilab
\construirScilab
No \verb+Scilab+, podemos computar os valores apresentados na tabela acima da seguinte forma:
\begin{verbatim}
deff('y=f(x)','y = exp(-x)/x^(1/2)')

a = 0
b = 1
n = 10
h = (b-a)/n
x = linspace(a,b,n+1)

// Regra do ponto médio
S_med = 0
for i = 1:n
S_med = S_med + f((x(i)+x(i+1))/2)*h
end
mprintf('Regra do ponto médio com %g subintervalos %.4e \n',n,S_med)

// Quadratura Gaussiana
S_GL = 0
t1 = -sqrt(3)/3
t2 = sqrt(3)/3
for i = 1:n
alpha = (x(i+1) - x(i))/2
Beta = (x(i+1) + x(i))/2
X1 = alpha*t1 + Beta
X2 = alpha*t2 + Beta
S_GL = S_GL + (f(X1)+f(X2)) * h/2
end
mprintf('Quadratura gaussiana com %g subintervalos %.4e \n',n,S_GL)
\end{verbatim}
\fi
%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%
Expand Down