What does this declaration do?
Ältere Kommentare anzeigen
Hello I am new to matlab, just want to know what is the importance of this xval such that values are returned differently when using 3 different variable instead of two variable?
sample code:
function g=dVdx(xval,yval,cst)
g = 4*cst(1) - (4*yval)/cst(1)^2 ;
by input
>> dVdx(0,5E-6,[0.02]) I will get an answer of 0.0300.
however
function g=dVdx(xval,yval)
g = 4*xval - (4*yval)/xval^2 ;
Input
>> dVdx(5E-6,0.02)
I will get a return number of -3.2000e+09 .
Akzeptierte Antwort
Weitere Antworten (1)
Star Strider
am 20 Feb. 2018
That appears to be an anonymous function to be used in one of the ODE solvers, such as ode45. The ODE solvers require that the first argument is the independent variable (here ‘xval’), and the second is the dependent variable (here ‘yval’). The third argument, ‘cst’, is an extra parameter.
The call to it in ode45 for example would be:
cst = 42; % Additional Parameter
tspan = [0 5]; % Time Range Or Vector
ic = 0; % Initial Condition
[x,y] = ode45(@(xval,yval) dVdx(xval,yval,cst), tspan, ic);
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!