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

Códigos de métodos numéricos para MATLAB


Enviado por   •  11 de Abril de 2019  •  Tareas  •  254 Palabras (2 Páginas)  •  422 Visitas

Página 1 de 2

CÓDIGOS DE MÉTODOS NUMÉRICOS PARA MATLAB

Código de Euler

%Metodo de Euler

clc

syms x

syms y

fprintf('\tResolucion de Ecuaciones Diferenciales por Metodo Euler');

f=inline(input('\n Ingrese la derivada:','s'));

x=input('\n Ingrese el valor de X inicial:');

xf=input('\n Ingrese el valor de X final:');

y=input('\n Ingrese el valor de Y inicial:');

h=input('\n Ingrese el paso:');

n=(xf-x)/h

disp(' x    y');

 

for i=1:n+1

    y1= feval(f,x,y);

    hy1=h*y1;

    fprintf('\n%0.1f %0.4f ',x,y);

    y=y+hy1;

    x=x+h;

end

Código Euler mejorado

function [x,y]=Euler_mejorado(f,a,b,ya,n)

h=(b-a)/n;

x=zeros(1,n+1);

y=zeros(1,n+1);

x(1)=a;

y(1)=ya;

for i=1:n

    x(i+1)=a+h*i;

    k1=feval(f, x(1), y(i));

    u(i+1)=y(1)+h*k1;

    k2=feval(f,x(i+1),u(i+1));

    y(i+1)=y(1)+h/2*feval(f, x(1), y(i));

end

y

Código de Runge-Kutta 4

function f

fprintf('\tResolucion de Ecuaciones Diferenciales por el Metodo RK4');

f=input('\ Ingrese la ecuacion diferencial:','s');

x0=input('\n Ingrese X Inicial: ');

x1=input('\n Ingrese X Final: ');

y0=input('n\ Ingrese Y Inicial: ');

n=input('\n Ingrese el numero de pasos: ');

h=(x1-x0)/n;

xs=x0:h:x1;

fprintf('\n''Pto  x0  y(x1)');

for i=1:n

    Pto=i;

    x0=xs(i+1);

    x=x0;

    y=y0;

    k1=h*eval(f);

    x=xs(i);

    y=y0+k1;

    k2=h*eval(f);

    y0=y0+(k1+k2)/2;

    fprintf('\n%2.0f%10.6f%10.6f\n',Pto,x0,y0);

end

fprintf('\n El punto aproximado Y(x1) es= %8.6f\n',y0);

Código de interpolación lineal

%Interpolacion lineal

clc

clear all

 

C=input('Valor dado =')

A=input('Valor a comparar A =')

FA=input('Valor a comparar F(A) = ')

B=input('Valor a comparar B =')

...

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