MATLAB Answers

Can not get exact exppresion due to cos function using Matlab symbolic toolbox

7 views (last 30 days)
K Hu
K Hu on 26 Oct 2020
Edited: K Hu on 26 Oct 2020
I am currently using Matlab to inplemente a groupe of function which is showing in the next picture.
briefly, this is a conditional expression with two variable, , repectively.
The objective is generate is expression assuming that σand T are time depending variable then drivate the expression to get the ODE form expression.
here is my code, i found an odd thing that the signal due to the term in expression 'g13(t)' rests always postive, even i'd well defined as a negative term.
syms xi_S0 sigma_crs sigma_crf xi_T0 C_M C_A M_s M_f A_s A_f Delta
syms g11(t) g12(t) g13(t) g14(t) T(t) sigma(t) a_A
%Delta= (1-xi_T0-xi_S0)/2 * cos(a_M*(T-M_f)) + (1 + xi_T0 - xi_S0)/2
%case 1
g11(t) =xi_T0/(1-xi_S0) + (1-(xi_T0+xi_S0))/(1-xi_S0) * ((1-xi_S0) /2 * cos(pi/(sigma_crs-sigma_crf) * (sigma(t)-sigma_crf-C_M * (T(t) - M_s))) + (1+xi_S0)/2)
%case 2
g12(t) = (2*xi_S0 -1) / (xi_S0-1) * Delta + (xi_S0-1 - Delta)/(xi_S0-1) * ((1-xi_S0)/2 * cos(pi/(sigma_crs-sigma_crf)*(sigma(t)-sigma_crf)+(1+xi_S0)/2))
%case 3
g13(t) = (xi_S0)/2 * (cos( a_A * ( T(t) - A_s - sigma(t)/C_A))+1)
the results is like this
>> g11
g11(t) =
((xi_S0 + xi_T0 - 1)*(xi_S0/2 - cos((pi*(sigma(t) - sigma_crf + C_M*(M_s - T(t))))/(sigma_crf - sigma_crs))*(xi_S0/2 - 1/2) + 1/2))/(xi_S0 - 1) - xi_T0/(xi_S0 - 1)
>> g12
g12(t) =
(Delta*(2*xi_S0 - 1))/(xi_S0 - 1) + (cos(xi_S0/2 + (pi*(sigma_crf - sigma(t)))/(sigma_crf - sigma_crs) + 1/2)*(xi_S0/2 - 1/2)*(Delta - xi_S0 + 1))/(xi_S0 - 1)
>> g13
g13(t) =
(xi_S0*(cos(a_A*(A_s - T(t) + sigma(t)/C_A)) + 1))/2 %the signal is changed
I'd like to ask if anyone know how to resolve this problem.
Best Rgds,
Kj Hu


Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Oct 2020
Irrelevant. cos(-x) = cos(x) so cos(a*f(x)) = cos(a*(-f(x)))


Show 1 older comment
K Hu
K Hu on 26 Oct 2020
Excuse me, i'd to ask to ask you if it's possible keep the 'unsimplify' form of the expression?
Walter Roberson
Walter Roberson on 26 Oct 2020
Yes, it is possible. However, it is a lot of work, requiring reprogramming the internal operations of the symbolic engine. I, for one, would literally not do it unless I was being paid to do it -- it is a waste of time.
The symbolic engine rewrites expressions a lot. The reasons include internal implementation of reducing storage for representations (which also has big impact on performace); the reasons also appear to include weird presentation preferences on the part of the original developers that make little sense when closely examined.
With expressions being rewritten a lot, you should basically never be doing exact comparisons of expressions unless you are programming at the MuPAD (internal symbolic language) level and have been very very careful to use MuPad hold() operators. Programmers at the MATLAB level do not have access to the hold() operator except by using evalin(symengine) or feval(symengine) to inject MuPAD code into the symbolic engine. If the MATLAB level receives an expression that includes a MuPAD hold() operator and the MATLAB level asks to display the expression, then you will get an error message and the symbolic engine will be reset -- so you have to really know what you are doing when you start working with internal hold() operators. And you have to have a special kind of stubborness, as the MuPad notebook (Integrated Development Environment) and all documentation of the MuPAD level has been removed. Beyond Here Be Dragons.
What you should be doing at the program level is instead comparing expressions using isAlways(A==B, 'unknown', false) ... and taking into account that there are legitimate reasons why a true equation might be undecideable.
K Hu
K Hu on 26 Oct 2020
The explication is very clear and thank you again to answer my question so quickly.
Since I don't have a large number of equations, I think I will do verification by myself.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by