Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.8K Views
|
15 Replies
|
1 Total Like
View groups...
Share
Share this post:

Solve error: not a valid variable

Posted 3 years ago

I have not used Mathematica in probably 10 years, so need some guidance. Specifically solving combinations of linear equations and circles. (Mohr circle analysis for engineers).

Anyway, hitting lots of roadblocks in syntax.

Here is an example: Solved for intercept of line y=mw+b with circle centered at xo and radius R. Coordinates are (x,w). You get two solutions:

x   =   -((b - (b + m xo)/(1 + m^2) +/- 
  Sqrt[(-b^2 m^2 + m^2 R^2 + m^4 R^2 - 2 b m^3 xo -   m^4 xo^2)/(1 + m^2)^2])/m)

for

w   =  (b + m xo)/(1 + m^2) +/-
 Sqrt[(-b^2 m^2 + m^2 R^2 + m^4 R^2 - 2 b m^3 xo -   m^4 xo^2)/(1 + m^2)^2]

I am not trying to solve for a special case of when I have a tangent. and the solution for this case as Sin[w], related to Mohr circles.

So for determinant:

(-b^2 m^2 + m^2 R^2 + m^4 R^2 - 2 b m^3 xo -  m^4 xo^2) = 0

There one two many variables here, should be three: but I have b, m, R and xo R and xo should set the circle, and m the line slope which is tangent. So I am trying to solve for one of these, so I can plug back into eqs for (x,w). In particular, I need to get Sin[phi], where Tan[phi=m.

When I enter:

ClearAll
y = Sin[phiw]
xo = (sig1 + J)/(1 + y) 
R = y*xo
m = Sqrt[y/(1 - y^2)]
b = J*m 
Solve[-b^2 m^2 + m^2 R^2 + m^4 R^2 - 2 b m^3 xo - m^4 xo^2 == 
0, b, Reals, 
Assumptions -> R > 0 && b > 0 && J > 0 && m > 0 && y > 0 && sig1 > 0]

I am getting an error for b=J*m as

Solve::ivar: J Sqrt[Sin[phiw]/(1-Sin[<<1>>]^2)] is not a valid variable.

in which case Solve just spits the entry back out at me.

I am sure this is some sort of beginner syntax issue.

Also, what is the command to clear everything. Clear All leaves variable definitions of something like that. I should have some beginning commands to always reset everything. Now I close and reopen Mathematica to ensure this.

POSTED BY: J E
15 Replies
Posted 3 years ago

Still working this problem of intersection of line and circle. Trying to simplify. Here is initial calculation:

Code 1:

ClearAll["Global`*"]
ClearAll[x, w, b, m, R, xo, phiw, y, J, solns1]
{x, w, b, m, R, xo, phiw} \[Element] Reals

Solve[{x, w} \[Element] 
   InfiniteLine[{{0, b}, {-b/m, 0}}] && {x, w} \[Element] 
   Circle[{xo, 0}, R], {x, w}]
FullSimplify[%, 
 0 < phiw < Pi/2 && R >= 0 && m >= 0 && b >= 0 && xo >= 0]

% /. m -> Tan[phiw]
solns1 = 
 FullSimplify[%, Reals, 
  Assumptions -> 0 < phiw < Pi/2 && b >= 0 && J >= 0 && xo >= 0 ]
x /. solns1[[2]]

This gives two solution for x and w. The algebraic is easier to follow, but the trig gives a simpler solution as last step. After some manipulation, I can clean these up. For example, for one solution, if I do by hand, I get:

Code 2:

m = Tan[phiw]

w = (b + m (xo + Sqrt[(1 + m^2) R^2 - (b + m xo)^2]))/(
  1 + m^2) = (b + m xo + m Sqrt[(1 + m^2) R^2 - (b + m xo)^2])/(
   1 + m^2) = (b + m xo)/(Sqrt[(1 + m^2)] Sqrt[(1 + m^2)]) + (
    m Sqrt[(1 + m^2) R^2 - (b + m xo)^2])/(
    Sqrt[(1 + m^2)] Sqrt[(1 + m^2)])
= (b + m xo)/(Sqrt[(1 + m^2)] Sqrt[(1 + m^2)]) + (
   m Sqrt[(1 + m^2) R^2 - (b + m xo)^2])/(
   Sqrt[(1 + m^2)] Sqrt[(1 + m^2)]) = (b + m xo)/(
    Sqrt[(1 + m^2)] Sqrt[(1 + m^2)]) + (
    m Sqrt[R^2 - (b + m xo)^2/(1 + m^2)])/Sqrt[(1 + m^2)] = 
   Ro/Sqrt[(1 + m^2)] + (m Sqrt[R^2 - Ro^2])/Sqrt[(1 + m^2)]

w = Ro Cos[phiw] + Sqrt[R^2 - Ro^2] Sin[phiw]

(b + m xo)^2/(1 + m^2) = Ro^2

x = (-b m + xo + Sqrt[(1 + m^2) R^2 - (b + m xo)^2])/(
  1 + m^2) = (-b m + xo )/(1 + m^2) + Sqrt[
    R^2 - (b + m xo)^2/(1 + m^2)]/Sqrt[(1 + m^2)] = (-b m + xo )/(
    1 + m^2) + Sqrt[R^2 - Ro^2]/Sqrt[(1 + m^2)]

x = -b Cos[phiw] Sin[phiw]  +  xo Cos[phiw]^2  + 
  Sqrt[R^2 - Ro^2] Sin[phiw]

Note m is the slope of the line. And you get a little simpler after using Tan[phi]. Ro is the specific circle radius that gives one solution, or the tangent line.

First question, how do I do these manipulations in Mathematica. Doing by defeats the purpose.

Second, when I try and equate the initial solution set with my manipulated set, they are clearly equal. But I can't get == or === or in combination with Expand or Reduce, can't get a True. This was the code for this comparison next. What is the secret to showing these are equal?

Workbook is attached.

Code 3:

ClearAll["Global`*"]
ClearAll[x, w, b, m, R, xo, phiw, y, J, solns1, x1, x2, s1, s2]
{x, w, b, m, R, xo, phiw} \[Element] Reals

m = Tan[phiw]
x1 = (-b m + xo + Sqrt[(1 + m^2) R^2 - (b + m xo)^2])/(1 + m^2)
x2 = -b Cos[phiw] Sin[phiw]  +  xo Cos[phiw]^2  + 
  Sqrt[R^2 - (b + m xo)^2/(1 + m^2)] Sin[phiw]
x1 == x2
s1 = FullSimplify[x1, Reals, 
  Assumptions -> 0 < phiw < Pi/2 && b >= 0 && J >= 0 && xo >= 0 ]
s2 = FullSimplify[x2, Reals, 
  Assumptions -> 0 < phiw < Pi/2 && b >= 0 && J >= 0 && xo >= 0 ]

s1 == s2
Attachments:
POSTED BY: J E
Posted 3 years ago
POSTED BY: J E

Have you seen http://reference.wolfram.com/language/tutorial/ManipulatingEquationsAndInequalities.html? If so, what's missing?

(I found it by going to the documentation page for Solve[] and clicking on one of the linked tutorials. About half the links are linked to some subsection of this tutorial.)

POSTED BY: Michael Rogers
POSTED BY: Gianluca Gorni
Posted 3 years ago

I have not seen a tutorial, in written or video format, that takes me through all the obvious steps in setting up simultaneous equations and simplification and manipulations of results. Is there one??? I little disappointed in Mathematica here. Lots of and lots of tutorials, but seems to be a whole lot less on this, which seems weird. Most are either over simplistic or focused on a random set of topics, and not core math and engineering calculations.

POSTED BY: J E

You can use SolveValues:

SolveValues[y == m*x + b, y]
y = First[%]

or the original Solve, with a more complicated syntax:

Solve[y == m*x + b, y]
y = y /. First[%]
POSTED BY: Gianluca Gorni
Posted 3 years ago

thanks, that worked on full simply and can have && for multiple assumptions, yes?

How can I restrict all calculations and variables to real domain, or eg. positive reals and zero. Is that possible for whole workbook? and does it get passed down to future expressions.

Or at least the results of trig functions.

also trying to assign the result of a solution back to one of the variables, see last post

POSTED BY: J E
Posted 3 years ago

Here is another, clearly something simple:

Solve[y == mx + b, y]
y = %

How do I assign a solution to the original variable after a solution

POSTED BY: J E

You should check the syntax of FullSimplify:

Solve[-b^2 m^2 + m^2 R^2 + m^4 R^2 - 2 b m^3 xo - m^4 xo^2 == 0, R]
% /. m -> Tan[phiw]
FullSimplify[%, 0 <= phiw < Pi/2]
POSTED BY: Gianluca Gorni
Posted 3 years ago

Making some small progress. Is there a tutorial that deals with detailed solving of simultaneous equations and with significant simplification. These involved combinations of squares and other powers, roots, and trig. I can clearly see patterns but can't get Mathematica to do its part. All is in real domain. For example:

ClearAll["Global`*"]
ClearAll[x, w, b, m, R, xo, phiw]
{x, w, b, m, R, xo, phiw} \[Element] Reals
$Assumptions = R >= 0 && m >= 0 && b >= 0 && xo >= 0
Solve[-b^2 m^2 + m^2 R^2 + m^4 R^2 - 2 b m^3 xo - m^4 xo^2 == 0, R]
FullSimplify[%, Reals, 
 Assumptions -> R >= 0 && m >= 0 && b >= 0 && xo >= 0]
% /. m -> Tan[phiw]
FullSimplify[%, Reals, 
 Assumptions -> 
  phiw >= 0 && phiw <= Pi/2 && R >= 0 && m >= 0 && b >= 0 && xo >= 0]

I get {{R -> Cos[phiw] Sign[Sec[phiw]] (b + xo Tan[phiw])}}

Clearly Sign of the sec should be positive, as Sec will be between 1 and + Inf, when phiw runs from 0 to Pi/2.

Reduce, fractor etc... expand?? what functions do I need.`

POSTED BY: J E
Posted 3 years ago

ClearAll does not clear all... for example, if x=sin(b), it will remember that.

In your code snippets above, you have just the raw head ClearAll. You need to pass it an argument(s). So, in your x example:

ClearAll[x]
(* or *) 
ClearAll["x"]

If you want to clear everything in the Global namespace:

ClearAll["Global`*"]
POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: J E

First, while Solve does accept complicated expressions as variables, it seems to rule out ones with certain heads, like Plus, Times, and Power. I surmise the reason is that these have internal simplification rules that are applied automatically. It seems difficult to disentangle b when b^2 m^2 becomes J^2 m^4 (or worse, since m has a complicated value). You could try solving for J instead of J*m and then recover b from J * m /. solution.

Second, the desired answer indicated in one of posts suggests you want to simplify or reduce, rather than solve for b. However, doing so indicates a problem in your setup. Maybe there's an error in one of the formulas or assumptions?

Simplify[-b^2 m^2 + m^2 R^2 + m^4 R^2 - 2 b m^3 xo - m^4 xo^2 == 0, 
 Assumptions -> R > 0 && b > 0 && J > 0 && m > 0 && y > 0 && sig1 > 0]
(*  False  *)

Reduce[-b^2 m^2 + m^2 R^2 + m^4 R^2 - 2 b m^3 xo - m^4 xo^2 == 0 && 
  R > 0 && b > 0 && J > 0 && m > 0 && y > 0 && sig1 > 0, Reals]
(*  False  *)

For reference, here are the definitions I copied:

y = Sin[phiw];
xo = (sig1 + J)/(1 + y);
R = y*xo;
m = Sqrt[y/(1 - y^2)];
b = J*m;
POSTED BY: Michael Rogers
POSTED BY: Gianluca Gorni
Posted 3 years ago

Above text not clear, not sure why post runs it all together. Repeated againenter code here:

   ClearAll
y = Sin[phiw]
xo = (sig1 + J)/(1 + y)
R = y*xo
m = Sqrt[y/(1 - y^2)]
b = J*m

Solve[-b^2 m^2 + m^2 R^2 + m^4 R^2 - 2 b m^3 xo - m^4 xo^2 == 
  0, b, Reals,
 Assumptions -> R > 0 && b > 0 && J > 0 && m > 0 && y > 0 && sig1 > 0]

The final answer should look something like :

   Sin[w/x] = -(((J + sig1) Sin[phiw])/(-sig1 + J Sin[phiw]))

btw m = tan[phiw], or tangent to the circle given by xo and R . Which are related as given above, with y = sin[phiw] .

POSTED BY: J E
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard