i'm trying to find the solution of a non-linear equation using the command solve. the problem is a trigonometric one, where the variables are all dependent of the symbol T.
syms ('T','real');
cth = (1-T^2)/(1+T^2);
sth = 2*T/(1+T^2);
A=[G1 G2; G4 G5];
B=[-G3; -G6]; %Gi for i=1:6 is function of T
X = A\B;
x=X(1); %function of T
y=X(2); %function of T
Eq= (x-b1x)^2+(y-b1y)^2 - d^2;
T_values = solve(Eq,T);
T_values = vpa(T_values);
theta = 2*atan(T)
it shows Warning message: Solutions are only valid under certain conditions. To
include parameters and conditions in the solution, specify the
'ReturnConditions' value as 'true'.
then changing to:
T_values = solve(Eq,T,'ReturnConditions',true)
displays the following error: Error using sym>tomupad (line 1539)
Unable to convert 'struct' to 'sym'.

댓글 수: 3

Torsten
Torsten 2022년 5월 30일
What do you get using the solve-command without the 'ReturnConditions' == true option ?
Maneet Kaur Bagga
Maneet Kaur Bagga 2023년 9월 13일
Hi Mohamed,
It would be easy to reproduce the code and solve the error if you provide the values of the variables.
syms ('T','real');
cth = (1-T^2)/(1+T^2);
sth = 2*T/(1+T^2);
A=[G1 G2; G4 G5];
B=[-G3; -G6]; %Gi for i=1:6 is function of T
X = A\B;
x=X(1); %function of T
y=X(2); %function of T
Eq= (x-b1x)^2+(y-b1y)^2 - d^2;
sol = solve(Eq,T,'returnconditions', true);
T_values = vpa(sol.T);
theta = 2*atan(T_values)
sol.conditions
vpa(sol.conditions)
We cannot execute because you have not defined the G variables.

댓글을 달려면 로그인하십시오.

답변 (1개)

Karan Singh
Karan Singh 2023년 11월 9일

0 개 추천

Hi Mohamed,
The solve function in MATLAB is used to solve equations. By default, it returns all solutions without any conditions. However, in some cases, the solutions are only valid under certain conditions. The warning message you're seeing is MATLAB telling you that the solutions it found might only be valid under certain conditions. By specifying ReturnConditions, true, you're asking MATLAB to return these conditions along with the solutions.
However, the error message you're seeing is because you're trying to assign the output of solve with ReturnConditions, true to a single variable T_values. When you specify ReturnConditions, true,solve returns three outputs: the solutions, the parameters in the solutions, and the conditions on the parameters.
To fix the error, you should assign the output of solve to three variables, like this:
[sol, params, conditions] = solve(Eq, T, 'ReturnConditions', true);
After this, you can use vpa to convert sol to a numeric approximation:
T_values = vpa(sol);
Attached below are the documentation links that you may find helpful:
Hope this helps!
Karan Singh Khati

댓글 수: 2

When you specify “ReturnConditions”, “true”, “solve” returns three outputs:
syms p
sol = solve(p^2 > 3, p, 'returnconditions', true)
sol = struct with fields:
p: [2×1 sym] parameters: x conditions: [2×1 sym]
sol.p
ans = 
sol.conditions
ans = 
Single output is fine.
However
vpa(sol)
Error using sym>tomupad
Unable to convert 'struct' to 'sym'.

Error in sym (line 273)
S.s = tomupad(x);

Error in vpa (line 46)
ss = sym(s);
That is because vpa() is not defined on a struct. You would need to vpa() something extracted from the struct
vpa(sol.p)
Karan Singh
Karan Singh 2023년 11월 9일
Thanks Walter for the correction!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2022년 5월 30일

댓글:

2023년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by