Metodo Del Disparo Lineal

Universidad Central del Ecuador Nombres: Gustavo Guachamin Bianca Palacios Laboratorio 2: Metodo del disparo lineal Pr

Views 72 Downloads 2 File size 569KB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

Universidad Central del Ecuador Nombres:

Gustavo Guachamin Bianca Palacios

Laboratorio 2: Metodo del disparo lineal Programa clc;clear; fprintf('\n \tMETODO DEL DISPARO DIRECTO\n') a=input('Ingrese el punto a:'); b=input('Ingrese el punto b:'); h=input('Ingrese el valor de h:'); y0=input('Ingrese el valor de y(a):'); beta=input('Ingrese el valor de y(b):'); N=(b-a)/h; T1={}; T2={}; Y1=[]; Y2=[]; f1=input('Ingrese p(x) ','s'); f2=input('Ingrese q(x) ','s'); f3=input('Ingrese r(x) ','s'); eq=input('Ingrese la ecuacion diferencial de la forma: dy/dx=f(x,y): ','s'); g1=input('Ingrese el valor inicial de la forma: y(a)=y0: ','s'); g2=input('Ingrese el valor inicial de la forma: y(b)=y0: ','s'); U1='y(2)'; v1='*y(1)'; v2='*y(2)'; U2 = strcat(f1,v2,f2,v1,f3); U3 = strcat(f1,v2,f2,v1); T1{1}=str2func(['@(x, y) ' U1]); T2{1}=str2func(['@(x, y) ' U1]); T1{2}=str2func(['@(x, y) ' U2]); T2{2}=str2func(['@(x, y) ' U3]); alpha(1)=y0; alpha(2)=0; alpha1(1)=0; alpha1(2)=1; s=dsolve(eq,g1,g2,'x') Fsegundo(a, b, 2, N, alpha, T1); Y1=A; Fsegundo(a, b, 2, N, alpha1, T2); Y2=A; syms x y x=a; y=y0; B=eval(s); R=B-y; fprintf('\n

t

u1,i

v1,i

W1,i

real

abs');

fprintf('\n%10.2f%10.6f%10.6f%10.6f%10.6f%10.6f\n',x,Y1(1),Y2(1),y,B,R); c=(beta-Y1(N+1))/Y2(N+1); for i = 1:N y= Y1(i+1)+c*Y2(i+1); x=a+i*h; B=eval(s); R=B-y; fprintf('\n%10.2f%10.6f%10.6f%10.6f%10.6f%10.6f\n',x,Y1(i+1),Y2(i+1),y,B, R); end

Función function Fsegundo(a, b, m, N, alpha, f) h = (b - a)/N; t = a; Y1=zeros(N+1, m); X=[]; X(1)=a; for j = 1:m Y1(1,j) = alpha(j); end k = zeros(4, m); for i = 1:N for j = 1:m k(1, j) = h*f{j}(t, Y1(i,:)); end for j = 1:m k(2, j) = h*f{j}(t + h/2, Y1(i,:) + (1/2)*k(1, :)); end for j = 1:m k(3, j) = h*f{j}(t + h/2, Y1(i,:) + (1/2)*k(2, :)); end for j = 1:m k(4, j) = h*f{j}(t + h, Y1(i,:) + k(3, :)); end for j = 1:m Y1(i+1,j) = Y1(i,j) + (k(1, j) + 2*k(2, j) + 2*k(3, j) + k(4, j))/6; end t = a + i*h; X(i+1)=t; end assignin('caller', 'A',Y1)

end