How can I exchange sqrt(-1) with 1i

3 views (last 30 days)
Felix Richter
Felix Richter on 25 May 2021
Edited: Paul on 25 May 2021
Hello all,
I want Matlab to show 1i instead of sqrt(-1). (Example see below)
I tried simplify, subs and other commands, however I cant get Matlab to exclude sqrt(-1) and show 1i.
syms g l K u
A_3 = [0 0 0; 0 0 1; 0 -g/l 0]
b_3 = [K; -K/l; 0]
% Ruhelagenvektor
x_0 = - A_3' * b_3 * u
% Eigenwerte des Systems
syms lambda
f = det(A_3 - lambda*eye(3)) == 0
lambda_s = solve(f,lambda)
% Edit: I am interested in lambda_s, sorry for the confusion!
% Eigenkreisfrequenz des Systems
% omega = simplify(lambda_s + [0 1i -1i]')
I hope you guys can help me with this.
Best regards
  3 Comments
Rik
Rik on 25 May 2021
Which release are you using?
syms g l K u
A_3 = [0 0 0; 0 0 1; 0 -g/l 0];
b_3 = [K; -K/l; 0];
% Ruhelagenvektor
x_0 = - A_3' * b_3 * u;
% Eigenwerte des Systems
syms lambda
f = det(A_3 - lambda*eye(3)) == 0;
lambda_s = solve(f,lambda);
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
% Eigenkreisfrequenz des Systems
omega = simplify(lambda_s + [0 1i -1i]')
omega = 
Felix Richter
Felix Richter on 25 May 2021
R2020b
To be clear, I want lambda_s to show sqrt(g/l)*1i instead of sqrt(-g/l).

Sign in to comment.

Accepted Answer

Paul
Paul on 25 May 2021
Edited: Paul on 25 May 2021
I thought that all that would be needed is to assume that g is positive:
syms g positive
sqrt(-g)
ans = 
Alas, this approach doesn't help in this problem:
syms g l K u
assume(g,'positive')
A_3 = [0 0 0; 0 0 1; 0 -g/l 0];
b_3 = [K; -K/l; 0];
% Ruhelagenvektor
x_0 = - A_3' * b_3 * u;
% Eigenwerte des Systems
syms lambda
f = det(A_3 - lambda*eye(3)) == 0;
lambda_s = solve(f,lambda)
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
lambda_s = 
simplify(lambda_s)
ans = 
The solution lambda_s is actually given in terms of (-g)^(1/2). Interestingly
(-g)^(1/2)
ans = 
simplify((-g)^(1/2))
ans = 
I guess the sqrt() function is unambigous but ^(1/2) is not. Try a substitution
syms temp
subs(subs(lambda_s,(-g)^(1/2),temp),temp,sqrt(-g))
ans = 
  3 Comments
Paul
Paul on 25 May 2021
Edited: Paul on 25 May 2021
I tried a single subs first
subs(lambda_s,(-g)^(1/2),sqrt(-g))
but that didn't yield the desired result. I don't know why.
Paul
Paul on 25 May 2021
Correction. Looks like a single subs() will work. Not sure why I thought otherwise. Looks like expand() will work as well.
syms g l K u
assume(g,'positive')
A_3 = [0 0 0; 0 0 1; 0 -g/l 0];
b_3 = [K; -K/l; 0];
% Ruhelagenvektor
x_0 = - A_3' * b_3 * u;
% Eigenwerte des Systems
syms lambda
f = det(A_3 - lambda*eye(3)) == 0;
lambda_s = solve(f,lambda)
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
lambda_s = 
subs(lambda_s,(-g)^(1/2),sqrt(-g))
ans = 
expand(lambda_s)
ans = 

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!