abs() in anonymous function

8 次查看(过去 30 天)
Ori Iger
Ori Iger 2020-2-27
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 个评论
Ori Iger
Ori Iger 2020-2-27
also got this in one attempt
Conversion to logical from symfun is not possible.
Geoff Hayes
Geoff Hayes 2020-2-27
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?

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2020-2-27
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.

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by