I'm trying to find solutions to variables in a system of non linear eqations, that represent a geometrical puzzle.

1 次查看(过去 30 天)
I entered the following code:
syms x y z S2 S h H R R2 AA t t2 OJ b r
eqns = [
S==x+y+z,
y^2==4*R^2+4*(R2)^2-8*R*(R2)*cosd(b),
x^2==r^2+h^2,
r/R==h/H,
r/R==x/S,
AA==2*S*sind(0.5*t),
t==360*R/S,
t2==360*(R2)/(S2),
S*sind(0.5*t)==(S2)*sind(0.5*t2),
OJ==S*cosd(0.5*t),
t==360*r/x
z==4.2,
b==12,
r==1,
R2==2.3];
S=solve(eqns,[x y z S2 S h H R R2 AA t t2 OJ b r])
After a lomg calculation, this is what I got:
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
S = struct with fields:
x: 15.519374279561498829840455111567
y: -37.927384706211756766808696524019
z: 4.2
S2: 493.7999929466430399611407129181
S: -18.208010426650257936968241412453
h: -65.794935418347018145616213397546
H: -3.707893983844770870611929394044e+33
R: -1.944599407619223280487166948252
R2: 2.3
AA: -12.036267472754629973712359640212
t: 22.903560444345897396478706663071
t2: -3.6850047349354341306483079435056
OJ: -17.573053681723424347298910447895
b: 12.0
r: 1.0
It is not possible because I nead possitive values.
So I tried:
assume (x>0 & y>0 & S2>0 & S>0 & h>0 & H>0 & R>0 & AA>0 & t>0 & t2>0 & OJ>0)
And then it calculated for a while, until it said that my session expired.
It happened each time only when I used "assume".
There are as much variables as equations. this problem represents a geometrical puzzle of a cone. and I know that there is a solution because I found the variables when I messured them from a sketch I made. I checked all of the equations and I know they are correct.
So I think there are two explanations:
  1. There is a non-logical connection between some of the equations (which I doubt it because I tried also inserting another equation with some of the variables)
  2. It is not compatible to solve using this code.
Assuming it is the second explanation, do you have an idea how to make the code compatible for this system of equations?
thank you!

回答(2 个)

Walter Roberson
Walter Roberson 2025-2-22
syms x y z S2 S h H R R2 AA t t2 OJ b r
eqns = [
S==x+y+z,
y^2==4*R^2+4*(R2)^2-8*R*(R2)*cosd(b),
x^2==r^2+h^2,
r/R==h/H,
r/R==x/S,
AA==2*S*sind(0.5*t),
t==360*R/S,
t2==360*(R2)/(S2),
S*sind(0.5*t)==(S2)*sind(0.5*t2),
OJ==S*cosd(0.5*t),
t==360*r/x
z==4.2,
b==12,
r==1,
R2==2.3];
S = vpasolve(eqns,[x y z S2 S h H R R2 AA t t2 OJ b r], repmat([0 inf], 15, 1))
S = struct with fields:
x: 2.5710805602650523901649443498794 y: 3.9808864911438406119932277773421 z: 4.2 S2: 25906612827076504826578.23269244 S: 10.751967051408893002158172127222 h: 2.3686399573115488011555705939165 H: 9.9053834295408366023921260947524 R: 4.181886486785335868457925145238 R2: 2.3 AA: 20.208304167000208122662114106703 t: 140.01894983908541530342764423347 t2: 0.000000000000000000030619407209922259904370042642957 OJ: 3.6757184533207860427320817359713 b: 12.0 r: 1.0
  2 个评论
Walter Roberson
Walter Roberson 2025-2-22
syms x y z S2 S h H R R2 AA t t2 OJ b r
eqns = [
S==x+y+z,
y^2==4*R^2+4*(R2)^2-8*R*(R2)*cosd(b),
x^2==r^2+h^2,
r/R==h/H,
r/R==x/S,
AA==2*S*sind(0.5*t),
t==360*R/S,
t2==360*(R2)/(S2),
S*sind(0.5*t)==(S2)*sind(0.5*t2),
OJ==S*cosd(0.5*t),
t==360*r/x
z==4.2,
b==12,
r==1,
R2==2.3].';
vars = [x y z S2 S h H R R2 AA t t2 OJ b r];
ess = eqns([1:3,5:6,9,13:15]);
vss = vars([1:3,5:6,9:10,14:15])
vss = 
length(vss)
ans = 9
sol1 = solve(ess,vss)
sol1 = struct with fields:
x: [4x1 sym] y: [4x1 sym] z: [4x1 sym] S: [4x1 sym] h: [4x1 sym] R2: [4x1 sym] AA: [4x1 sym] b: [4x1 sym] r: [4x1 sym]
resteqn = setdiff(eqns, ess)
resteqn = 
eqns2 = subs(resteqn, sol1)
eqns2 = 
v2 = setdiff(vars, vss)
v2 = 
sol2 = solve(eqns2(1,[2 6]), v2([2 6]))
sol2 = struct with fields:
OJ: (S2*cos((pi*t)/360)*sin((23*pi)/(10*S2)))/sin((pi*t)/360) t2: 828/S2
eqns3 = subs(eqns2(:,[1 3:5]), sol2)
eqns3 = 
wait... notice the duplicate t= entries. We solved initially for 9 variables (out of 15 equations), leaving 6 variables. The fact that after substitution we get duplicate t entries implies that there is redundant information in the equations -- and also implies that we have one too few equations to be able to calculate all of the variables.
John D'Errico
John D'Errico 2025-2-23
编辑:John D'Errico 2025-2-23
Well done. I was wondering about that possibility. The real issue is there are redundant equations. This is not at all uncommon. It makes the problem unsolvable in any unique way from this set of equations without providing more information. Thus we need another equation that is not dependent on those we have already seen.

请先登录,再进行评论。


John D'Errico
John D'Errico 2025-2-22
编辑:John D'Errico 2025-2-22
A problem is, we don't actually know what is the geometric system you are trying to solve, nor have you told us the solution you think to be true. That means we can't check your equations, even though you claim they are correct. You have been far too vague in this respect. And there is likely no easy way for us to reverse engineer the original problem from a set of equations. And even if we could, then we still would not know if that was the real problem you started with.
Nonlinear systems of equations often have multiple solutions. In fact, that is the case far more often than not. A problem is, a solver needs to use starting values to converge to the solution you happen to like. If you give it nothing to work with, vpasolve uses a set of random numbers. And random numbers are pretty much never going to be a good choice for your problem. (Sometimes they are a good idea. But not here.)
So the first thing I would do, since we cannot give you better advice on a problem we don't know anything about, is to give vpasolve as starting values, what you think is the solution. Does it converge to something close, something that makes sense? If it does not, then there is likely an issue with your equations.
For example, even though you have a system of equations with as many equations as unknowns, it is often the case that people do not realize that some of their equations provide duplicate information. And in that case, you would have infinitely many solutions, but the solver would not know it.
So start by doing as I suggest. Do you get something reasonable given that initial point? We would expect, that IF your equations are correct, to see a result that is just a refinement of your start point, since anything you measured from a sketch will not be exact.

类别

Help CenterFile Exchange 中查找有关 Equation Solving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by