abs() in anonymous function

조회 수: 8 (최근 30일)
Ori Iger
Ori Iger 2020년 2월 27일
답변: Steven Lord 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