Академический Документы
Профессиональный Документы
Культура Документы
FOZ DO IGUAÇU
2016
LISTA 10 - INTEGRAIS NUMÉRICAS
1) Programas de Integração Numérica
Euler Progressivo e Regressivo
Trapézio
Simpson 1/3
function I = simp13func(f,a,b,n)
%método simpson 1/3
%entrada é uma função
%n é o numero de segmentos
z = linspace(a,b,np);
z = z';
xi = 0;
wi = 0;
for i = 2:(length(z)-1)
if mod(i,2)==0
w = f(z(i));
wi = wi + w;
else
x = f(z(i));
xi = xi + x;
end
end
I = (b-a)*(f(a) + 4*wi + 2*xi + f(b))/(3*n);
end
function I = simp13vetor(x,y)
%metodo simpson 1/3
%entrada são dois vetores x e y
n = length(x) - 1;
ui = 0;
wi = 0;
for i = 2:(length(x)-1)
if mod(i,2)==0
w = y(i);
wi = wi + w;
else
u = y(i);
ui = ui + u;
end
end
I = (x(n+1) - x(1))*(y(1) + 4*wi + 2*ui + y(n+1))/(3*n);
end
Simpson 3/8
function I = simp38func(f,a,b)
% Simpson 3/8 entrada com uma função
%Regra 3/8 de simspon em sua forma mais simples, quando o numero de pontos
%é 4
n = 3;
np = 4;
z = linspace(a,b,np);
z = z';
I = (b-a)*( f(z(1)) + 3*f(z(2)) + 3*f(z(3)) + f(z(4)) )/8;
end
2) Resolução do Circuito RLC
Equacionamento
A corrente na fonte será igual a somatória da corrente de cada elemento do circuito:
𝑖 = 𝑖𝑅 + 𝑖𝐿 + 𝑖𝐶
Substituindo a equação da corrente do resistor, indutor e do capacitor:
𝑉(𝑡) 1 𝑑𝑉(𝑡)
𝑖= + ∫ 𝑉(𝑡)𝑑𝑡 + 𝐶
𝑅 𝐿 𝑑𝑡
Daí, será calcula a integral da tensão utilizando os métodos numéricos. A derivada
da tensão em relação ao tempo será calculada a partir da seguinte expressão:
𝑑𝑉(𝑡) 𝑉 − 𝑉𝑎𝑛𝑡
=
𝑑𝑡 ℎ
Algoritmo
clear;clc;close all;
%resolução do circuito lista 10;
%% DADOS PADRÃO
%RLC paralelo
ti = 0; tf =50*10^-3; h = 1*10^-3;
%Dados do circuito
R = 100; L = 176*10^-3; C = 10*10^-6;
Vrms = 127; f = 60; theta = 0;
t = (ti:h:tf);
n_t = length(t);
for k=1:n_t-1
if k == 1
v_ant=0;
else
v_ant=v(t(k-1));
end
%euler progressivo:
I = v(t(k))*(t(k+1)-t(k));
i(1,k) = v(t(k))/R + (1/L)*I + C*(v(t(k))-v_ant)/h;
%euler regressivo:
I = v(t(k+1))*(t(k+1)-t(k));
i(2,k) = v(t(k))/R + (1/L)*I + C*(v(t(k))-v_ant)/h;
%trapezoidal:
I = 0.5*(v(t(k))+v(t(k+1)))*(t(k+1)-t(k));
i(3,k) = v(t(k))/R + (1/L)*I + C*(v(t(k))-v_ant)/h;
%simpson_13:
I = (t(k+1)-t(k))*(v(t(k))+4*v(t(k)+h/2)+v(t(k+1)))/(6);
i(4,k) = v(t(k))/R + (1/L)*I + C*(v(t(k))-v_ant)/h;
%simpson_38:
I = (t(k+1)-
t(k))*(v(t(k))+3*v(t(k)+h/3)+3*v(t(k)+2*h/3)+v(t(k+1)))/(6);
i(5,k) = v(t(k))/R + (1/L)*I + C*(v(t(k))-v_ant)/h;
end
subplot(3,2,1);
plot(t,i(1,:));
subplot(3,2,2);
plot(t,i(2,:));
subplot(3,2,3);
plot(t,i(3,:));
subplot(3,2,4);
plot(t,i(4,:));
subplot(3,2,5);
plot(t,i(5,:));
subplot(3,2,6);
plot(t,i);
axis([ti tf -6 6])
Gráficos
Gráficos estão disponíveis no ANEXO 1(Δt = 1ms) e ANEXO 2(Δt =
1us).
LISTA 11 - EQUAÇÕES DIFERENCIAIS
1) Programas de Equações Diferenciais
Método de Euler
y(1) = y0;
l = length(t);
h = t(2)-t(1);
for i = 1:(length(t) - 1)
y(i+1) = y(i) + f(t(i),y(i))*h;
end
Método de Heun
function [y,e] = heun(f,ti,tf,h)
%método de Heun para resolução de EDOs
%saída é um vetor y e o erro e
%o vetor y contém duas linhas, uma para os valores de y¹ e outra para y²
t = (ti:h:tf);
y = zeros (2,length(t));
y0 = 2;
y(1,1) = y0;
y(2,1) = y0;
es = 0.01;
e = 2*es;
for i = 1:length(t)-1
for i=1:length(t)-1
k1=f(t(i),Y(i));
k2=f(t(i)+h/2,Y(i)+k1*h/2);
Y(i+1)=Y(i)+k2*h;
end
t=linspace(ti,tf,np);
l=length(t);
h= t(2)-t(1);
Y(1) = y0;
for i=1:l-1;
k1=f(t(i),Y(i));
k2=f(t(i)+1/2*h,Y(i)+1/2*k1*h);
k3=f(t(i)+1/2*h,Y(i)+1/2*k2*h);
k4=f(t(i)+h,Y(i)+k3*h);
Y(i+1)=Y(i)+1/6*(k1+2*k2+2*k3+k4)*h;
end;
%inicio do algoritmo
y1(1) = y10;
y2(1) = y20;
x = (xi:h:xf);
for i=1:(length(x) - 1)
k11 = f1(x(i),y1(i),y2(i));
k12 = f2(x(i),y1(i),y2(i));
h1 = y1(i) + 0.5*k11*h;
h2 = y2(i) + 0.5*k12*h;
k21 = f1(x(i)+0.5*h,h1,h2);
k22 = f2(x(i)+0.5*h,h1,h2);
h1 = y1(i) + 0.5*k21*h;
h2 = y2(i) + 0.5*k22*h;
k31 = f1(x(i)+0.5*h,h1,h2);
k32 = f2(x(i)+0.5*h,h1,h2);
h1 = y1(i) + k31*h;
h2 = y2(i) + k32*h;
k41 = f1(x(i)+h,h1,h2);
k42 = f2(x(i)+h,h1,h2);
𝑑𝑖 𝑉 − 𝑅. 𝑖 − 𝑉𝑐
=
𝑑𝑡 𝐿
Essas equações serão inseridas nos programas como sendo "f1" e "f2"
respectivamente.
Algoritmos
Método de Euler
clear;clc;close all;
%resolução do circuito lista 11;
%método de euler;
%% DADOS PADRÃO
%RLC série
ti = 0; tf =1; h = (1/60)/512;
%Dados do circuito
R = 1; L = 1e-2; C = 1e10;
Vrms = 127; f = 60; theta = 0;
t = (ti:h:tf);
n_t = length(t);
v = Vrms*sqrt(2)*cos(2*pi*60*t + deg2rad(theta));%Fonte de tensão senoidal
%Funções
f1 = @(t,Vc,i,v,R,L,C) i/C; %formula relacionada a dVc/dt
f2 = @(t,Vc,i,v,R,L,C) (v - R*i - Vc)/L;%formula relacionada a di/dt
Vc = zeros(1,n_t);
i = zeros(1,n_t);
Vc(1) = 0;
i(1) = 0;
%% método de Euler
for w=1:n_t-1
end
plot(t,i);
grid on;
Método de Heun
clear;clc;close all;
%resolução do circuito lista 11;
%método de Heun;
%% DADOS PADRÃO
%RLC série
ti = 0; tf =1; h = (1/60)/512;
%Dados do circuito
R = 1; L = 1e-2; C = 1e10;
Vrms = 127; f = 60; theta = 0;
t = (ti:h:tf);
n_t = length(t);
%Funções
f1 = @(t,Vc,i,v,R,L,C) i/C; %formula relacionada a dVc/dt
f2 = @(t,Vc,i,v,R,L,C) (v - R*i - Vc)/L;%formula relacionada a di/dt
Vc = zeros(1,n_t);
i = zeros(1,n_t);
Vc(1) = 0;
i(1) = 0;
for w=1:n_t-1
Vcja = Vc(w+1);
ija = i(w+1);
%% DADOS PADRÃO
%RLC série
ti = 0; tf =1; h = (1/60)/512;
%Dados do circuito
R = 1; L = 1e-2; C = 1e10;
Vrms = 127; f = 60; theta = 0;
t = (ti:h:tf);
n_t = length(t);
%Funções
f1 = @(t,Vc,i,v,R,L,C) i/C; %formula relacionada a dVc/dt
f2 = @(t,Vc,i,v,R,L,C) (v - R*i - Vc)/L;%formula relacionada a di/dt
Vc = zeros(1,n_t);
i = zeros(1,n_t);
Vc(1) = 0;
i(1) = 0;
for w=1:n_t-1
end
plot(t,i);
grid on;
%% DADOS PADRÃO
%RLC série
ti = 0; tf =1; h = (1/60)/512;
%Dados do circuito
R = 1; L = 1e-2; C = 1e10;
Vrms = 127; f = 60; theta = 0;
t = (ti:h:tf);
n_t = length(t);
%Funções
f1 = @(t,Vc,i,v,R,L,C) i/C; %formula relacionada a dVc/dt
f2 = @(t,Vc,i,v,R,L,C) (v - R*i - Vc)/L;%formula relacionada a di/dt
Vc = zeros(1,n_t);
i = zeros(1,n_t);
Vc(1) = 0;
i(1) = 0;
for w=1:n_t-1
k11 = f1(t(w),Vc(w),i(w),v(w),R,L,C);
k12 = f2(t(w),Vc(w),i(w),v(w),R,L,C);
h1 = Vc(w) + 0.5*k11*h;
h2 = i(w) + 0.5*k12*h;
k21 = f1(t(w)+0.5*h,h1,h2,v(w),R,L,C);
k22 = f2(t(w)+0.5*h,h1,h2,v(w),R,L,C);
h1 = Vc(w) + 0.5*k21*h;
h2 = i(w) + 0.5*k22*h;
k31 = f1(t(w)+0.5*h,h1,h2,v(w),R,L,C);
k32 = f2(t(w)+0.5*h,h1,h2,v(w),R,L,C);
h1 = Vc(w) + k31*h;
h2 = i(w) + k32*h;
k41 = f1(t(w)+h,h1,h2,v(w),R,L,C);
k42 = f2(t(w)+h,h1,h2,v(w),R,L,C);