defining symbolic piecewise function

조회 수: 15 (최근 30일)
Francesco Collini
Francesco Collini 2017년 12월 20일
답변: Francesco Collini 2019년 2월 28일
Good evening, I have an issue trying to define a piecewise symbolic function in matlab.
I already tried using the piecewise predefined function as shown in the next piece of code:
a = sym('a'); l = sym('l');
r_i = symfun(r_c(a) + r_1, a); l_i = symfun((pi/2)*r_c(a), a); l_2 = symfun(l_i(a) + r_2 - r_i(a), a);
r = symfun(piecewise((0 <= l) && (l < l_i(a)),...
r_1 + r_c(a) * (1 - cos(l / r_c(a))),...
(l_i(a)<=l) && (l<l_2(a)),...
r_i(a) + l - (pi/2) * r_c(a)),...
[l, a]);
but it shows this error "Conversion to logical from sym is not possible.".
I guess it is because I can not use a symbolic function in the chain of inequalities, but I do not know how to fix this, so please could anyone help me? Thankyou very much and merry Christmas!!
PS
This piece of code is contained in a function.m file.

채택된 답변

Francesco Collini
Francesco Collini 2019년 2월 28일
I found out that the solution for this problem is:
a = sym('a'); l = sym('l');
r_i = symfun(r_c(a) + r_1, a); l_i = symfun((pi/2)*r_c(a), a); l_2 = symfun(l_i(a) + r_2 - r_i(a), a);
r = symfun(piecewise((0 <= l) & (l < l_i(a)),...
r_1 + r_c(a) * (1 - cos(l / r_c(a))),...
(l_i(a)<=l) & (l<l_2(a)),...
r_i(a) + l - (pi/2) * r_c(a)),...
[l, a]);
The problem was in the definition of the intervals, where a single character "&" must be used instead two "&&" to define an interval under more than one condition.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by