Essays.club - Ensayos gratis, notas de cursos, notas de libros, tareas, monografías y trabajos de investigación
Buscar

MÉTODOS NUMÉRICOS.

Enviado por   •  5 de Julio de 2018  •  727 Palabras (3 Páginas)  •  221 Visitas

Página 1 de 3

...

adecuado’)

delta=0.0005;

max1=10;

[c,err,yc]=falsa1(a,b,delta,max1)

Nombre del programa: Prog01.sce

4) Desde el editor de SCILAB cargue en SCILAB los archivos: fun1, falsa1 y desde la ventana de comandos ejecute Prog01, observe los resultados en la consola de comandos del SCILAB

// Programa biseccion

clc;close;

clear;funcprot(0);

function x=bisection(a, b, f)

N=100; // define max. number of iterations

PE=10^-4 // define tolerance

if (f(a)*f(b) > 0) then

// error(’my error message’)

error(’ no root possible f(a)*f(b) > 0 ’)

// checking if the decided range is containing a root

abort;

end;

if(abs(f(a)) <PE) then

error( ’ solution at a ’) // seeing i f there is an approximate root at a ,

abort;

end;

if(abs(f(b)) < PE) then // seeing i f there is an approximate root at b ,

error(’ solution at b ’ )

abort;

end;

x=(a+b)/2

for n=1:1:N // i n i t i a l i s i n g "for" loop ,

p=f(a)*f(x)

if p<0 then b=x ,x=(a+x)/2; // checking for the required conditions ( f(x)*f(a)<0) ,

else

a=x

x=(x+b)/2;

end

if abs(f(x))<=PE then break // instruction to come out of the loop after the required condition is achived ,

end

end

disp(n,’ no. of iterations =’) // display the no . of iterations took to achive required condition ,

endfunction

// The equation y=x.^3-5*x+1==0 has real roots .

// the graph of this function can be observed here .

xset(’window’,2);

x=-2:.01:4; // defining the range of x .

deff(’[y]=f(x)’,’y=x.^3-5*x+1’);

//deff(’[y]= f(x)’,’y=y=x.^3-5*x+1’);

// defining the function

y=feval(x,f);

a=gca();

a.y_location = ’origin’;

a.x_location = ’origin’;

plot(x,y)

// instruction to plot the graph

title(’y=x.^3-5*x+1’)

// from the above plot we can infre that the function has roots between

// the intervals (0 ,1) ,(2 ,3)

// since we have been asked for the smallest positive root of the equation,

// we are intrested on the interval (0 ,1)

// a=0;b=1,

// we c all a user−defined function ’ bisection ’ so as to find the approximate

// root of the equation with a defined permissible error .

xgrid

r=bisection(0,1,f);

disp(r, ’raíz =’)

...

Descargar como  txt (4.5 Kb)   pdf (48.2 Kb)   docx (13.7 Kb)  
Leer 2 páginas más »
Disponible sólo en Essays.club