0
$\begingroup$

There are two lists as follows:

Vars = 
  {{(x1)Cos[x2], Sin[x2], 0, (x3) (Sin[x2])}, {(Cos[x2]) (Sin[x4]), 
    (x3)Cos[x4], 1, x1}};
Const = {{1, 0, 0, 1}, {0, 1, 1, 2}};

Using Vars and Const, I want to make a system of equations like :

SysEqu = 
  {(x1)Cos[x2]==1, Sin[x2]==0, 0==0, (x3) (Sin[x2])==1,
   (Cos[x2])(Sin[x4])==0, (x3)Cos[x4]==1, 1==1, x1==2}

Then a UI asks about the VARIABLES to be solved and finally :

sol1 = NSolve[SysEqu, VARIABLES];

I know that NSolve generally may have some problems to give exact answers for any kind of equation. Other approaches could be acceptable instead of NSolve[].

Could you please help me with this code?!


P.S.

To setup my equations, I used this code:

SetEqual = MapThread[Set, {Vars, Const}, 2];

However, some errors appear that two of them are :

Tag Times in x2 Sin[x2] is Protected.
Cannot assign to raw object 1.

$\endgroup$
1
  • 2
    $\begingroup$ 1 isn't a variable, so naturally it cannot be assigned anything. $\endgroup$
    – Feyre
    Jul 3, 2015 at 8:19

1 Answer 1

3
$\begingroup$

Your problem is the Set. Set means you're assigning something to a variable (=), x2 Sin[x2] is not a variable. Try Equal[] instead, this is equivalent to ==.

Vars = {{(x1) Cos[x2], Sin[x2], 
    0, (x3) (Sin[x2])}, {(Cos[x2]) (Sin[x4]), (x3) Cos[x4], 1, x1}};
Const = {{1, 0, 0, 1}, {0, 1, 1, 2}};
MapThread[Equal, {Vars, Const}, 2]

yields the output:

{{x1 Cos[x2] == 1, Sin[x2] == 0, True, 
  x3 Sin[x2] == 1}, {Cos[x2] Sin[x4] == 0, x3 Cos[x4] == 1, True, 
  x1 == 2}}

The trues show up because you're asking 0==0 and 1==1.

$\endgroup$
3
  • $\begingroup$ Thank you so much for helping. However, my major problem is still unsolved; a GUI that solve the sol1 . $\endgroup$
    – Shellp
    Jul 5, 2015 at 7:35
  • $\begingroup$ @Shellp Your request for a UI is pretty broad. One problem is that you have six equations in four unknowns. NSolve[SysEqu] "works" as it should, but there are no solutions. $\endgroup$
    – Michael E2
    Jul 5, 2015 at 14:08
  • $\begingroup$ @Shellp I'm afraid that this system doesn't have solutions, you're asking: $\sin{x_{2}}==0, x_{3}\sin{x_{2}} == 1$ This means that $x_{2}=k\pi, k\in \mathbb{Z}$, and $x_{2}\ne k\pi$ at the same time. $\endgroup$
    – Feyre
    Jul 6, 2015 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.