Mathematicas: How to solve equation in terms of the variable - wolfram-mathematica

I have a quick question. Say you got x+y=2x, and you want to solve this equation in terms of y as some function of x in mathematica, how do you do that?

just use the Solve function. In your case it becomes :
Solve[x + y == 2 x, y]
that gives:
{{y -> x}}

Related

Analytic Solution for ODE

I HAVE EQUATION
y - 7(e^x/x)dydx=0
How to find analytic solution in Mathematica?
My work :
I simplify the equations become y'=yx/7e^x
I run in Mathematica,
DSolve[y'[x] == (y[x] x)/(7 e^x), y[x], x]
I get result:
{{y[x] -> E^(1/7 E^-x (-1 - x)) C[1]}}.
Questions:
Are my simplifications correct?
Do I type correct code in step 2?
How to find exact value of C in the result, because I want to use to find y' for given x value
Thank you for the answer

Ignore parts of an equation with multiple variable in Mathematica

I want to use the linear version of a somewhat big equation which is outputted by my Mathematica code - For simplicity I will here use the example equation:
Test = 3 x + x y + 8 y
Now, I want to use only the first order term, so that for x that will be 3 and for y that will be 8. I have tried to get those using
Coefficient[Test, x]
Coefficient[Test, y]
However these give me for x:
3+y
and for y:
8+x
Is there anyway I can use Mathematica to ignore the terms that depend in both xy simultaneously?

Calculating product by addition

This is an algorithm question that I've been struggling with. I figured I could get some insight here. I need to make the following function in Haskell:
Declare the type and define a function that takes two numbers as input and finds their product by addition. That is, add the first number, as many times as second number, to itself.
My problem is that this is basically just multiplying two numbers together, but it says that I need to do it with addition. Does anyone have any clue on how to do this?
This is all I can come up with (it's not right): (x + x) * y
Thank you
if a is the first number and b the second
sum $ take a $ cycle [b]
should do ot
mult (x, y):
sum = 0
for 1 to y:
sum = sum + x
return sum
This is just the algorithm. I do not know Haskell. So the lambda expression in the other answer may be more appropriate. Also, I use an intermediate variable.
PS: forget the previous embarrassing recursive algorithm
Work it out by induction.
We know the answer to one simple (the simplest) problem: multiplying anything by 0 yields 0. So we write:
mul x 0 = 0
Now, the inductive step: we can build a solution to a bigger problem, if we know a solution to the smaller problem; that way we can always reduce any big problem to the smallest problem, for which we know the solution. So, for any y, the solution for y+1 can be found by adding x to the solution for y: mul x (y+1) = x + (mul x y). In Haskell we can't write (y+1) on the left hand side, so we write equivalently:
mul x y = x + (mul x (y-1))
This function will keep adding x until y is zero.
Try this also
multiply::(Num a,Eq a) => a -> a -> a
multiply a 0 = 0
multiply a b = a + multiply a (b - 1)
main = print $ multiply 5 7

Gradient of a function at specific x,y,z values in Mathematica

I'm looking for a way to find the gradient of a function and then evaluate the output at specific x,y,z values. Thus far, I have
Needs["VectorAnalysis`"]
Clear[x, y, z]
v1 = Grad[x^2 + y^2 + z^2 - 9, Cartesian[x, y, z]]
which outputs
{2 x, 2 y, 2 z}. How could I evaluate this at x=2,y=2, and z=1, for instance? This seems trivial for the function above, but it would be immensely useful for more complicated functions. Thank you very much for any advice.
You can Replace the variables by values using Rule:
v1/.{x->2,y->2,z->1}

Obtain x as result for Re[x] in mathematica

I'm trying to obtain the real part of the result of an operation which involves an undefined variable (let's say x).
How can I have Mathematica return x when I execute Re[x] if I know that x will never be a complex number? I think this involves telling Mathematica that x is a real, but I don't know how.
In my case the expression for which I want the real part is more complicated than a simple variable, but the concept will remain the same.
Some examples:
INPUT OUTPUT DESIRED RESULT
----- ------ --------------
Re[x] Re[x] x
Re[1] 1 1
Re[Sin[x]] Re[Sin[x]] Sin[x]
Re[1+x+I] 1 + Re[x] 1+x
Re[1 + x*I] 1-Im[x] 1
You can use for example the input Simplify[Re[x], x \[Element] Reals] which will give x as output.
Use ComplexExpand. It assumes that the variables are real unless you indicate otherwise. For example:
In[76]:= ComplexExpand[Re[x]]
Out[76]= x
In[77]:= ComplexExpand[Re[Sin[x]]]
Out[77]= Sin[x]
In[78]:= ComplexExpand[Re[1+x+I]]
Out[78]= 1+x
Two more possibilities:
Assuming[x \[Element] Reals, Refine[Re[x]]]
Refine[Re[x], x \[Element] Reals]
Both return x.
It can at times be useful to define UpValues for a symbol. This is far from robust, but it nevertheless can handle a number of cases.
Re[x] ^= x;
Im[x] ^= 0;
Re[x]
Re[1]
Re[1 + x + I]
Re[1 + x*I]
x
1
1 + x
1
Re[Sin[x]] does not evaluate as you desire, but one of the transformations used by FullSimplify does place it in a form that triggers Re[x]:
Re[Sin[x]] // FullSimplify
Sin[x]

Resources