Issue with integrating a function.

5 vues (au cours des 30 derniers jours)
Sam
Sam le 19 Mar 2024
I am trying get an integral for int_0^u f(x) dx with f(x)=v/(1+w*x^2), u=3, v=13, w=8. This is what I have tried to no success, am I understanding the function incorrectly or have it in the wrong order?
eqn=v/1+(w*x^2)
function intf=integrate(eqn)
intf=inegrate(intf,0,u)
end

Réponses (1)

Steven Lord
Steven Lord le 19 Mar 2024
There are several problems with this code segment. Off the top of my head I see three serious problems.
First, nowhere in the code have you defined the variables v, w, x, or u. Therefore any attempt to use the values of those variables will cause MATLAB to throw an error.
Second, while you have defined a function named integrate, you never call the function.
Third, even if you did call integrate you attempt to use intf (which isn't defined at the time you attempt to use it as an input) to call inegrate (which I assume is a typo and you meant to call integrate.) If I'm correct that you made a typo, calling integrate would call integrate with too many inputs. But if your integrate function were defined to accept four inputs, calling integrate would call integrate which would call integrate which would call integrate which would call integrate .... MATLAB would eventually error out because it detects that you're in an infinite recursive scenario.
I strongly suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB. This will include how to define variables and how to call functions.
The integral function will also be of use to you, as would the int function if you wanted to use Symbolic Math Toolbox to integrate symbolically.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by