abs() in anonymous function
Mostra commenti meno recenti
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 Commenti
Geoff Hayes
il 27 Feb 2020
Ori - what attempts did you make? What syntax errors did you observe? Why can't you just replace J with abs(J) in your function "body" (leave the input parameter as is)?
Ori Iger
il 27 Feb 2020
Ori Iger
il 27 Feb 2020
Geoff Hayes
il 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?
Risposte (1)
Steven Lord
il 27 Feb 2020
0 voti
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.
Categorie
Scopri di più su Mathematics in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!