I am trying to use a script to run simpsons rule to numerically integrate a function, it keeps giving me an error.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos

0 comentarios
Respuestas (2)
Walter Roberson
el 6 de Jul. de 2017
You are trying to pass parameters to a script. You cannot do that. In order to be able to pass parameters to something, it has to be a function (or a class constructor.)
A script is a .m file whose first executable token is not either "function" or "classdef". You cannot pass parameters to them.
You need to add a "function" header line to your code.
0 comentarios
James Tursa
el 6 de Jul. de 2017
Editada: James Tursa
el 6 de Jul. de 2017
A script is an m-file that has MATLAB statements in it only, without a function statement. E.g.,
File myfun1.m:
x = 2*a;
File myfun2.m:
function x = myfun2(a)
x = 2*a;
return
end
The first file, myfun1.m, is a script file. It simply executes MATLAB statements based on the variables in your workspace. The second file, myfun2.m, is a function file. It takes an input argument and returns an output.
Your simpsonsrule.m file is apparently a script file like myfun1.m, but you are trying to call it like a function that takes inputs and returns outputs. To do that, you need to add in the function statement and set the return variables.
0 comentarios
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!