Error: Invalid expression log equation
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sabrina Garland
le 17 Avr 2021
Commenté : Walter Roberson
le 2 Mai 2023
I am trying to solve an equation in Matlab mobile.
Following is the code -
syms t a
eqns =-a*log((3*t/4)*(3-t^2)/(2-t))-(1-a)*log((1/t^2)*((3-2*t)/(2-t)))+a*((1-t)^2)*(3-t)/((2-t)*(3-t^2)-(1-a)*(1+t)/(3-2*t))*((t*(-18+21*t-7*t^3+2*t^4)*(log((3-2*t)*(3-t^2)/(2*t(2-t)^2))))/(36-39*t+13*t^3-4*t^4+a*(-18+27*t-18*t^2+5*t^3)))+2*log((1/3)*(3-t^2)/(2-t))+t*log((4*(t^3)/27)*((3-t^2)/(3-2*t)))-2*t==0;
But I keep getting the error
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
0 commentaires
Réponse acceptée
Walter Roberson
le 17 Avr 2021
syms t a
eqns =-a*log((3*t/4)*(3-t^2)/(2-t))-(1-a)*log((1/t^2)*((3-2*t)/(2-t)))+a*((1-t)^2)*(3-t)/((2-t)*(3-t^2)-(1-a)*(1+t)/(3-2*t))*((t*(-18+21*t-7*t^3+2*t^4)*(log((3-2*t)*(3-t^2)/(2*t(2-t)^2))))/(36-39*t+13*t^3-4*t^4+a*(-18+27*t-18*t^2+5*t^3)))+2*log((1/3)*(3-t^2)/(2-t))+t*log((4*(t^3)/27)*((3-t^2)/(3-2*t)))-2*t==0;
% 12 1 2 1 2 10 1 0 12 1 23 2 3 210 12 1 0 1 0 12 1 2 1 2 1 2 1 2 10 12 3 2 3 45 4 5 4 5 6 5 4321 2 3 210 12 1 2 1 2 10 12 3 2 1 23 2 3 210
The bracket count is okay, it all balances out, and the error message you indicate does not occur. A different error occurs instead.
Have a look at the place the bracket count reaches 6:
% (2*t(2-t)^2)
% 5 6 5 4
Notice that you are trying to index t by 2-t . That is an error. You probably want (2*t*(2-t)^2)
15 commentaires
Tomas
le 2 Mai 2023
the U in this case is a random variable. So, should I just change it to a different random variable to clear that issue?
Walter Roberson
le 2 Mai 2023
f_inv = @(x) log(-2*(2-x))
This will be complex-valued unless x >= 2.
It is not at all clear why you do not instead write
f_inv = @(x) log(2*(x-2))
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Assumptions dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!