-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmmq.m
66 lines (53 loc) · 1.43 KB
/
mmq.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function [UaproxGra, pontos] = mmq( coef, P, a, b )
syms x; clc;
%Calcular o número n de coeficientes de u
n = 0;
for i = 1:length(coef)
if coef(i) ~= 0;
n = n + 1;
end
end
%Calculo da função da solução aproximada u(i) = alpha(i) * phi(i)
%Phi = {(x - x^2), (x^2 - x^3), (x^3 - x^4), ...}
%-----------------------------------------------------------------
for i = 1:n
u(i) = (x^(i) - x^(i+1));
end
%Derivadas
%--------------------------------------------------------
du=diff(u); %Derivada primeira de u
d2u=diff(du); %Derivada segunda de u
%Psi = L(phi)
%--------------------------------------------------------
for i = 1:n
psi(i)=coef(1)*d2u(i) + coef(2)*du(i) + coef(3)*u(i);
end
%Função Residual --> E = lu - P
%--------------------------------------------------------
for i = 1:n
for j = 1:n
%Calculo da função Lu
Lu = coef(1)*d2u(j) + coef(2)*du(j) + coef(3)*u(j);
%Integral o residual*psi no dominio (a,b) forçado a 0
A(i,j) = int(Lu*psi(i),x,a,b);
end
%Matriz dos termos independentes
B(i) = -int(psi(i)*P, x, a, b);
end
%Valores dos Alphas
disp('Alphas:')
Alphas = A\B'
%ua - Solução Aproximada
disp('Solução Aproximada:')
ua = 0;
for i=1:n
ua = ua + Alphas(i) * u(i);
end
ua
%Função Aproximada nos pontos escolhidos
pontos = a:0.01:b;
UaproxGra = 0;
for i = 1:n
UaproxGra = UaproxGra + (Alphas(i)*pontos.^(i) - Alphas(i)*pontos.^(i+1));
end
end