Maple, converting from polar to cartesian expression? - maple

In Maple I have a polar expression
and I need to convert it to a Cartesian expression. Though the convert function of Maple doesn't seem to have an option for this.
I currently have a by-hand conversion:
Though there has to be a proper automatic version, isn't there?
Thanks!

The general mechansisms are,
G:=a+b*I;
G := a + I b
H:=convert(G,polar);
H := polar(|a + I b|, argument(a + I b))
evalc(H);
a + I b
So, for your example with given operator specifying the modulus,
r := (theta,a,epsilon) -> a*(1-epsilon^2)/(1+epsilon*cos(theta)):
evalc( polar( r(theta,a,epsilon), theta ) );
/ 2 \ / 2 \
a \-epsilon + 1/ cos(theta) I a \-epsilon + 1/ sin(theta)
---------------------------- + ------------------------------
1 + epsilon cos(theta) 1 + epsilon cos(theta)

Related

How can I use unknown variables in Matlab?

For example, I have an operation from Wolfram Alpha: det({s+1,0},{0,s+1}}). Wolfram solves it and shows me a result: s^2 + 2s + 1. How can I do such things (with unknown variables) in Matlab?
With Symbolic Math Toolbox, this can be done using the following:
syms s;
det([s+1,0 ; 0,s+1])
which gives this:
ans =
(s + 1)^2
and if you want to get the expanded form i.e. s^2 + 2*s + 1, you can use expand function as follows:
syms s;
expand(det([s+1,0 ; 0,s+1]))

Can someone explain the simplification of this boolean algebra equation?

I think I missed reading a theorem or postulate or something..
The equation is: wy + wxz + xyz
According to my professor, the simplification is (which she didn't explain how):
wy + xz(w'y + wy')
= wy + xz (w XOR y)
Where did that (w'y + wy') came from??
I tried to calculate it but so far I only got: (w+x)(w+y)(w+z)(x+y)(y+z)
In a Boolean expression + is XOR and * is AND. This is the same as identifying true with 1 and false with 0, with the only special convention that 1 + 1 = 0 (or 2 = 0 if you wish.)
With these definitions both + and * are commutative, i.e., a + b = b + a and a * b = b * a. In addition, the distributive law is also valid a * (b + c) = a * b + a * c. Note also that the * operator is usually implicit in the sense that we write ab instead of a * b.
Applying these properties to the expression wy + wxz + xyz, there are some few obvious transformations you can do:
wy + wxz + yxz (commute x with y)
wy + (w + y)xz (prev plus distribute xz)
wy + xz(w + y) (prev plus commute (w + y) with xz
Note that the last one is wy + xz(w XOR y) because + is nothing but XOR.
ADDENDUM
Regarding the expression of your professor, let's recall that a' = 1 - a by definition. So
w'y + wy' = (1 - w)y + w(1 - y) - def
= y - wy + w - wy - distribute
= y + w - simplify (a + a = 0 always)
= w + y - commute
which shows that s/he was right.

How can I get MATLAB to numerically solve a particularly nasty system of equations?

I have four parameters, t1,t2, theta1, and theta2. I want to find a solution (there can potentially be infinitely many) to the following system of equations:
t1*cos(theta1) + t2*cos(theta2) + 2*t1*t2*sin(theta1 + theta2) = t1*sin(theta1) + t2*sin(theta2) + 2*t1*t2*cos(theta1 + theta2) + 1
t1*cos(theta1) + t2*cos(theta2) + t1*sin(theta1) + t2*sin(theta2) = 2*t1*t2*sin(theta1 + theta2) + 2*t1*t2*cos(theta1 + theta2) + 1
2*t1^2*t2^2 + sin(theta1)*t1*t2^2 + sin(theta1 + theta2)*t1*t2 + 1 = sin(theta2)*t1^2*t2 + t1^2 + sin(theta1)*t1 + t2^2
Since there are more parameters than equations, we have to impose further restrictions to identify a specific solution to this system. Right now I don't really care which solution is picked, as long as it isn't trivial (like all the variables equaling zero).
My current method is to set the third equation to 0.5, solving for t1 and t2 in terms of theta1 and theta2, and substituting these expressions into the first two equations to solve for theta1 and theta2. However, MATLAB is trying to do this symbolically, which is extremely time-consuming. Is there a way I can get some approximate solutions to this system? I can't exactly plot the surfaces represented by these equations and look at their intersection, because each side of the equations involves more than two parameters, which means it can't be visualized in three dimensions.
You can use fsolve to do this.
First, you need to create anonymous functions for the residuals of the three equations. I'm going to create a vector x where x = [t1; t2; theta1; theta2]. That makes the residuals:
r1 = #(x) x(1)*cos(x(3)) + x(2)*cos(x(4)) + 2*x(1)*x(2)*sin(x(3) + x(4)) - (x(1)*sin(x(3)) + x(2)*sin(x(4)) + 2*x(1)*x(2)*cos(x(3) + x(4)) + 1);
r2 = #(x) x(1)*cos(x(3)) + x(2)*cos(x(4)) + x(1)*sin(x(3)) + x(2)*sin(x(4)) - (2*x(1)*x(2)*sin(x(3) + x(4)) + 2*x(1)*x(2)*cos(x(3) + x(4)) + 1);
r3 = #(x) 2*x(1)^2*x(2)^2 + sin(x(3))*x(1)*x(2)^2 + sin(x(3) + x(4))*x(1)*x(2) + 1 - (sin(x(4))*x(1)^2*x(2) + x(1)^2 + sin(x(3))*x(1) + x(2)^2);
Then, we need to make a single function that is a vector of those three residuals, since fsolve tries to get this vector to be zero:
r = #(x) [r1(x); r2(x); r3(x)]
Now, we call fsolve. I picked an arbitrary starting point:
>> [x, fval, exitflag] = fsolve(r, [0.5,0.5,pi/4,pi/4])
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
> In fsolve at 287
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
x =
0.9654 0.5182 0.7363 0.7344
fval =
1.0e-10 *
-0.0090
0.2743
-0.0181
exitflag =
1
You can ignore the warning. x is the four values you were looking for. fval is the value of the residuals. exitFlag == 1 means we found a root.

plot a nonlinear function matlab

I'm very new to Matlab and have problem plotting this nonlinear 2D function graph using Matlab.
a lot of errors generated after the below is run.
fun1 = 20 + 10 + 15;
fun2 = 20 + (x * 0.00125 ) + 15;
fun3 = (x * 0.0025) + 15;
fplot(fun1,[0 8000])
fplot(fun2,[8000 16000])
fplot(fun2,[16000 positive infinity])
I appreciate a lot to your efforts and kindness for replying my question
Best Regards
Your first three expressions do not define functions. Please read the documentation about the correct syntax.
fun1 = #(x)(20 + 10 + 15);
First create a file fun.m which contains your function definition
function y = fun(x)
if x < 8000
y = 20 + 10 + 15;
elseif x < 16000
y = 20 + (x * 0.00125) + 15;
else
y = x * 0.0025 + 15;
end
end
Then you can plot it with
fplot(#fun, [0 24000])
which results in
If you do some reading in fplot you will find out that
for fplot(fun,limits)
fun must be
The name of a function
A string with variable x that may be passed to eval, such as 'sin(x)', 'diric(x,10)', or '[sin(x),cos(x)]'
A function handle
so in your case you need to change all of you fun to strings just add ' before and after the expression
as for the last line change it to be
fplot(fun2,[16000 inf])
although i don't think this would give you any good results

How take coordinates from Vector in maple

Is any way to get coordinates from Vector in maple? For example if I would like have function f(V) = sin(V[0]) + cos(V[1]) + V[2]
Where V = (x,y,z). Is it possible in maple?
In Maple a Vector starts its indexing from 1 (not from 0). So the first entry is V[1], rather than V[0].
Also, a Vector can be constructed with either the Vector command or its angle-bracket shortcut notation. Round brackets do not construct a Vector, as they are delimiters for either grouping or arguments of function application.
restart:
f := V -> sin(V[1]) + cos(V[2]) + V[3]:
W := Vector([a,b,c]):
f(W);
sin(a) + cos(b) + c
Y := <3,7,11>:
f(Y);
sin(3) + cos(7) + 11
An Array is more flexible and can be constructed so as to start its indexing from 0.
g := V -> sin(V[0]) + cos(V[1]) + V[2]:
W := Array(0..2,[q,r,s]):
g(W);
sin(q) + cos(r) + s
Note that the LinearAlgebra package deals with Matrix and Vector. Also, some arithmetic operations (such as .) act in an elementwise manner for Array and not a way you might expect for doing computational linear algebra.
restart:
F := Array(1..3,[q,r,s]):
F . F;
[ 2 2 2]
[q , r , s ]
U := Vector[row]([q,r,s]):
U . U;
_ _ _
q q + r r + s s
Note the complex conjugation occuring in the last example. And in contrast with Matrix structures, 2-dimensional Arrays are also multiplied elementwise under the . operator.