How can I exchange sqrt(-1) with 1i
3 views (last 30 days)
Show older comments
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
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);
% Eigenkreisfrequenz des Systems
omega = simplify(lambda_s + [0 1i -1i]')
Accepted Answer
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)
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)
simplify(lambda_s)
The solution lambda_s is actually given in terms of (-g)^(1/2). Interestingly
(-g)^(1/2)
simplify((-g)^(1/2))
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))
3 Comments
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)
subs(lambda_s,(-g)^(1/2),sqrt(-g))
expand(lambda_s)
More Answers (0)
See Also
Categories
Find more on Linear Algebra 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!