abs() in anonymous function
6 views (last 30 days)
Show older comments
Hi there
I solved the previous problem by introducing an anonymous function
f2 = @(t,J) lambda * tau_0 * (0.5*(tanh(J-theta_i)-tanh(-theta_i))) * (0.25*(1-(tanh(-theta_0))^2)) * [ ((1-J)^mu)*(3/2-(3/2-t/tau_0)*(exp(-t/tau_0)))/(tau_p) - 3*alpha*(J^mu)/(tau_m) ] ;
The function "J" appearing in the derivative (f2) is supposed to be "abs(J)" .
All attempts I did ended up with syntax errors..
Thanks in advance :)
Uri
4 Comments
Geoff Hayes
on 27 Feb 2020
Ori - you may need to show more of your code so that we can see how the variables to your anonymous function are defined. Are all of the variables scalars? Are any arrays? The error message seems to be telling you that you are trying to use a negative or non-integer index into an array. I do see that you are using square brackets in your code...what is the intention here? Is this valid syntax?
Answers (1)
Steven Lord
on 27 Feb 2020
If this error started occurring when you added an abs call inside the anonymous function, you most likely have defined a variable named abs, and your attempts to call the function abs are being interpreted as an attempt to index into the variable abs. Rename or remove the variable, recreate the anonymous function, and call ode45 with the recreated function handle.
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!