So recently i've been asked to do a project about Simpson's composite rule and i worked the whole thing with matlab r2017, but my teacher asked me to do it on Matlab 7 (because the computers of the school only do have Matlab 7.0 R14 2004) when i tried to execute my program on this version of matlab i've faced so many problems and didn't work because of librairies i think so please what can be the alternative for this code in an ancient machine and thanks for your reply in advance

      function IntegralS = SimpsonComposite()
%     Inputs :
%     --------
      funstr = input('Please enter your function : ', 's');
      f = str2func( ['@(x) ' funstr ] );
      a = input('Please enter the point a : ');
      b = input('Please enter the point b : ');
      n = input('Please enter how many time you want to use this formula : ');
      h = (b-a)/(2*n);
      xi = a:h:b;
%     The primitive of your function :
%     --------------------------------
      syms x;
      fprintf('The primitive of your function is : %s \n', int(f,x));
%     calculate the integral :
%     ------------------------
      fprintf('The value of this integral is : %s\n ', integral(f,a,b));
%     The value of this integral with Simpson's composite is  : 
%     ---------------------------------------------------------
      Integrale = h/3 * (f(xi(1)) + (f(xi(end))) + 4.*sum(f(xi(2:2:end))) + 2.*sum(f(xi(3:2:end-2))));
      fprintf('The value of this integral via Simpson''s composite is : %s\n ', Integrale);
      disp(' ');
%     The points of this integral are :  
%     ---------------------------------
      disp ('The points of this integral are : ');  
      disp(sym(xi));
%     The results of these points with our function :  
%     -----------------------------------------------
      disp ('The results of these points with our function : ');  disp(f(xi));
%     The value of h is :
%     -------------------
      fprintf('The value of h is : %s', sym(h));
%     The error bound is :
%     --------------------
      syms x;
      Errorbound =  integral(f,a,b) -  Integrale;
      fprintf('The error bound is : %s\n', Errorbound);

1 comentario

Walter Roberson
Walter Roberson el 20 de Abr. de 2018
Please do not close Questions that have an Answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Abr. de 2018

Comentada:

el 20 de Abr. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by