Error in matlab?
Show older comments
[A,B,t,r]=solve('e^(-i*k*a)+r^(i*k*a)=A*e^(-i*q*a)+B*e^(i*q*a)', ...
'A*e^(i*q*a)+B*e^(-i*q*a)=t*e^(-i*k*a)', ...
'i*k*(e^(-i*k*a)-r*e^(i*k*a))=i*q*(A*e^(-i*q*a)-B*e^(i*q*a))', ...
'i*q*(A*e^(-i*q*a)-B*e^(-i*q*a))=i*k*t*e^(i*k*a)')
end
Error:Expression or statement is incorrect--possibly unbalanced (,{,or[.
Image of code

7 Comments
Walter Roberson
on 13 Sep 2018
Note that MATLAB does not know e^something as being exponential. You probably need exp() instead.
Walter Roberson
on 13 Sep 2018
Note that when you use quoted strings that any variable name in the string will not be replaced with the value of the variable within the workspace. Because of that, you are defining a series of equations involving variables named
A B a e k q r t
For a total of 8 variables. The i in the strings will be treated as the imaginary unit rather than as a variable.
madhan ravi
on 13 Sep 2018
Edited: madhan ravi
on 13 Sep 2018
syms k a A e B t r q
[A,B,t,r]=solve(e^(-i*k*a)+r^(i*k*a)==A*e^(-i*q*a)+B*e^(i*q*a)', A*e^(i*q*a)+B*e^(-i*q*a)==t*e^(-i*k*a), i*k*(e^(-i*k*a)-r*e^(i*k*a))==i*q*(A*e^(-i*q*a)-B*e^(i*q*a)), i*q*(A*e^(-i*q*a)-B*e^(-i*q*a))==i*k*t*e^(i*k*a),A,B,t,r)
also use == instead of = within the equations. I tried solving it but Matlab returned empty syms
Walter Roberson
on 13 Sep 2018
Specifying equations by strings became invalid for solve as of r2018a. In current releases you should use syms and build up symbolic expressions, or else use str2sym()
Walter Roberson
on 14 Sep 2018
The diagram is a bit difficult to make out. Is it correct that
q = sqrt(k^2+2*m*mu_0/A^2)
If so then there is no closed form solution for all of the variables. Potentially A is fully resolvable (not completely sure yet), but B and t involve roots of an exponential / polynomial mix that has no closed form solution.
... Assuming q is as per the above.
Eugene
on 14 Sep 2018
Walter Roberson
on 14 Sep 2018
simplify() exists in MATLAB, but maple simplify is mostly more powerful. maple simplify is not enough to solve this problem.
Please verify whether q = sqrt(k^2+2*m*mu_0/A^2)
Answers (1)
Denis Perotto
on 14 Sep 2018
Are you sure, that these equations aren't wrong? For example, you can divide 3rd equation by i. The system is nonlinear and MATLAB cannot solve it symbolically:
Ты уверен, что у тебя правильно записана система уравнений? В 3-м уравнении, как минимум, можно сократить на i. Система нелинейная и в символьном виде MATLAB ее не решает:
syms r A B t k a q;
equations = [exp(-1i * k * a) + r ^ (1i * k * a) == A * exp(-1i * q * a) + B * exp(1i * q * a), ...
A * exp(1i * q * a) + B * exp(-1i * q * a) == t * exp(-1i * k * a), ...
1i * k * (exp(-1i * k * a) - r * exp(1i * k * a)) == 1i * q * (A * exp(-1i * q * a) - B * exp(1i * q * a)), ...
1i * q * (A * exp(-1i * q * a) - B * exp(-1i * q * a)) == 1i * k * t * exp(1i * k * a)];
vars = [r A B t];
S = solve(equations, vars);
As a result, struct S has null fields and we get a warning:
В результате S имеет нулевые поля и вылезает предупреждение:
Warning: Cannot find explicit solution
Please, check your equations or solve them numerically.
Либо ищи ошибку в записи уравнений/упрощай их и пытайся решить. Либо не мучайся и решай численно.
3 Comments
Eugene
on 14 Sep 2018
Walter Roberson
on 14 Sep 2018
Nonlinear equations often do not have closed form solutions.
Denis Perotto
on 15 Sep 2018
Не решает, потому что система нелинейная; большинство нелинейных систем в символьном виде не решаются, поэтому я и посоветовал решать численно. Если численно ну совсем никак, попробуй упростить выражения, поделив на i 3 и 4 уравнения, как минимум. Может, можно экспоненты в sin и cos преобразовать по формуле Эйлера, поиграйся, авось MATLAB и решит. За основу можешь взять мой код, он рабочий. Только уравнения новые впиши.
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!