Undefined function 'piecewise' for input arguments of type 'double'. or 'Conversion to logical from sym is not possible.' errors
조회 수: 1 (최근 30일)
이전 댓글 표시
function deflectionV=Deflection_ptbui3(deflPos)
syms deflPos
deflectionV=piecewise((0<deflPos)&&(deflPos<=120),800*(deflPos)^3-13.68*10^6*(deflPos)-2.5*(deflPos)^4,(120<deflPos)&&(deflPos<=240),800*(deflPos)^3-13.68*10^6*(deflPos)-2.5*(deflPos)^4+(2.5*(deflPos-120)^4),(240<deflPos)&&(deflPos<=360),800*(deflPos)^3-13.68*10^6*(deflPos)-2.5*(deflPos)^4+(2.5*(deflPos-120)^4)+(600*(deflPos-240)^3));
deflectionV=(1/3.19E9)*deflectionV;
end
This is my code for the function for my piecewise, but whenever I call for it in my actual script, I get a 'Conversion to logical from sym is not possible.' error.
I've been trying to do this problem where i put the user input into a piecewise function.
Before when I didn't have the syms, it would also just give me 'Undefined function 'piecewise' for input arguments of type 'double'. So i'm not entirely sure whats going on and my teacher nor TA's know very much about the function. And if you think it isn't gonna work, please let me know so I can get the closure to delete this mess of a function. :)
댓글 수: 0
답변 (1개)
Ajay Pattassery
2020년 2월 18일
The logical operator && is a short-circuit operator which means the second operand is only evaluated when the result is not fully determined by the first operand. Refer here for more information.
In your case logical and (&) need to be used.
deflectionV=piecewise((0<deflPos)&(deflPos<=120),800*(deflPos)^3-13.68*10^6*(deflPos)-2.5*(deflPos)^4,(120<deflPos)&(deflPos<=240),800*(deflPos)^3-13.68*10^6*(deflPos)-2.5*(deflPos)^4+(2.5*(deflPos-120)^4),(240<deflPos)&(deflPos<=360),800*(deflPos)^3-13.68*10^6*(deflPos)-2.5*(deflPos)^4+(2.5*(deflPos-120)^4)+(600*(deflPos-240)^3));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!