ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

EJERCICIO EN MALTAB


Enviado por   •  26 de Octubre de 2015  •  Resúmenes  •  299 Palabras (2 Páginas)  •  143 Visitas

Página 1 de 2

EJERCICIO EN MALTAB

PROGRAMA:

function [A,B,solucion] =diffinitasedo(a,b,alpha,beta,N )

%UNTITLED2 Summary of this function goes here

%   Detailed explanation goes here

h=(b-a)/N;

A=zeros(N-1);

B=zeros(N-1,1);

t=a+h:h:b-h;

%p=(2*t)./(1+t.^2);

%q=(-2)./(1+t.^2);

%r=ones(1,N-1);

p=10*ones(1, N-1);

q=-25*ones(1, N-1);

r=zeros(1, N-1);

d= 2+ h^2*q;

sd=(h/2)*p-1;

dd=(-h/2)*p-1;

A=zeros(N-1);

B=zeros(N-1,1);

%%CONSTRUCCION DE LA MATRIZ A

for i=1:N-1

    if i==1

        A(i,i)=d(i);

        A(i,i+1)=sd(i);

    elseif i==N-1

        A(i,i-1)=dd(i);

        A(i,i)=d(i);

    else

        A(i,i-1)=dd(i);

        A(i,i)=d(i);

        A(i,i+1)=sd(i);

    end

end

%CONSTRUCCION DEL VECTOR COLUMNA B

for i=1:N-1

    if i==1

        B(i) =-h^2*r(i) + ((h/2)*p(i) + 1)*alpha;

    elseif i==N-1

        B(i)=-h^2*r(i)+ (-(h/2)*p(i) + 1)*beta;

    else

        B(i)=-h^2*r(i);

    end

end

%SOLUCION DEL SISTEMA AX=B

solucion=inv(A)*B

%GRAFICA DE LA SOLUCION

x=a:h:b;

y=[alpha,solucion',beta];

plot(x,y)

end

EJERCICIO:

>> a=0, b=1, alpha=1, beta=0, N=4

a =

     0

b =

     1

alpha =

     1

beta =

     0

N =

     4

>> [A,B,solucion] =diffinitasedo(a,b,alpha,beta,N )

solucion =

    2.9453

    3.8457

   19.7779

A =

    0.4375    0.2500         0

   -2.2500    0.4375    0.2500

         0   -2.2500    0.4375

B =

    2.2500

         0

         0

solucion =

    2.9453

    3.8457

   19.7779

>> hold on

>> x=0:0.01:1;

>> y1=exp(5*x)-x.*exp(5*x);

>> plot (x,y1,'r')

>>

...

Descargar como (para miembros actualizados)  txt (1.6 Kb)   pdf (84.5 Kb)   docx (10.9 Kb)  
Leer 1 página más »
Disponible sólo en Clubensayos.com