A specific analytic integration can not be done - matlab

The following definite integral can not be done in "Matlab R2013a", although it can be done analytically in other mathematics programs. Why?
syms r M c real
assume(M>0)
assume(c>M)
y=1/(sqrt((r^2-M)*(r^2/c^2-1))*r);
int(y,r,c,inf)
The answer is
atanh(sqrt(M)/c)/sqrt(M).
Thanks

There's another way to write the solution:
-log((-M-c^2+2*sqrt(M)*c)/(M-c^2))/(2*sqrt(M))
I don't use Matlab, but can you try assuming that M does not equal c^2?

Related

How to use Matlab's linprog or intlinprog to yield a MAXIMUM solution to optimization?

So I need to use MatLab to solve an optimization problem but this question doesn't have to be for a specific problem, this question is for optimization in general.
How do you get linprog() or intlinprog() to get the maximum solution? As far as I know, these functions only find the minimum solution to optimization problems but I need the maximum solutions.
How do I get the linear programming functions on matlab to return the maximum solution of an optimization problem?
Thanks in advance!
From documentation entries for the function linprog the function is called like that
x = linprog(f, A, b)
in order to find min f'x.
If you instead call
x = linprog(-f, A, b)
you will find max f'x
Reverse the sign of the objective function f (vector of multipliers) with a negative sign. Maximizing a function is the same as minimizing the negative of the same function.

Matlab: Solving a equation: Warning: Explicit solution could not be found

I have a equation like this:
2^n * exp((-p*k*n*(k*n-(k+1)*2^t)))/((k+1)^2*2^(2*t+1))- 1=0.
I tried using the follwing code, but it gives me a warning that "Explicit solution could not be found".
syms n k t p positive;
S=solve(2^n * exp((-p*k*n*(k*n-(k+1)*2^t)))/((k+1)^2*2^(2*t+1))- 1,n,'IgnoreAnalyticConstraints', true);
S
Is there a way to solve the equation in terms on n?
Thanks in advance
Short answer: NO
MATLAB tries to find an "Explicit" solution, one in which variable n is expressed in terms of the other variables. In your case, the solution is "Implicit", meaning that variable n cannot be isolated and thus appears on both sides of the equation.
I used a different tool and here is what I got.
[e^((-k^2-k)np2^t+k^2n^2p)=2^(-2t+n-1)/(k^2+2*k+1)]
As you can see, n appears on both sides.
You might want to take a look at this post

MATLAB: How to solve linear system modulo m

Does anyone know what functions are available for solving linear systems when the equations are actually congruences mod m? The desire is to solve a linear system (Ax = b) for values x in which "Ax is congruent to b"
A discussion of how to perform gaussian elimination in this situation can be found here, but I was hoping to use MATLAB rather than attempting to do it by hand.
Have a look at the lincon() method found here:
http://www.mathworks.com/matlabcentral/fileexchange/32856-system-of-linear-congruences/content/lincon.m

intersection of two line

how can one obtain coordinates of intersections of two line diagrams with given expression or equation?
for example:
L1= sin(2x) , L2= Ln(x); or anything else.
Amazingly, nobody has yet suggested using the function designed to do this in matlab. Use fzero here. Fzero is a better choice than fsolve anyway, which requires the optimization toolbox. And, yes, you could do this with Newton's method, or even bisection or the secant method. But reinventing the wheel is the wrong thing to do in general. Use functionality that already exists when it is there.
The problem at hand is to find a point where
sin(2*x) == log(x)
Here log(x) refers to the natural log. Do this by subtracting one from the other, then looking for a zero of the result.
fun = #(x) sin(2*x) - log(x);
Before you do so, ALWAYS plot it. ezplot can do that for you.
ezplot(fun)
The plot will show a single root that lies between 1 and 2.
fzero(fun,2)
ans =
1.3994
Since you tagged with matlab, you can do it with fsolve(#(x)sin(2*x)-log(x),1) which gives 1.3994 (1 is the initial starting point or guess). The y-coordinate is log(1.3994) = 0.3361.
That is, you use fsolve, pass it the function you want to solve for the zero of, in this case sin(2*x) == log(x) so you want sin(2*x) - log(x) == 0 (log is the natural log in matlab).
If you already have functions set up like, e.g. L1 = #(x)sin(2*x) and L2 = #(x)log(x) (or in functions L1.m and L2.m) you can use fsolve(#(x)L1(x)-L2(x),1).
In general, you have to solve the equation L1(x) = L2(x). If you don't know from the beginning what L1 and L2 are (linear, polynominal...) then the only solution is numeric solving for example with Netwon algorithm. The problem is then reduced to finding roots (zeros) of function f(x) = L1(X) - L2(X).
This is not a trivial question: what you're asking for is a general method for solving any mathematical equation.
For instance, you could consider using the bisection method, or Newton's method.
There is no general answer.
As a general non-analytic solution, when you have any 2 curves described by 2 sets of points, there is great submission at File Exchange - Fast and Robust Curve Intersections.

Setting the variables of Solve in MATLAB

In MATLAB, I have an equation a*x+b=0 for which I have a and b defined during execution. What is the best way I can solve the equation using what I've set for a and b.
I guess that you are going to have to use num2str() and related functions to build the equation in the string form that solve() requires. That shouldn't be too difficult should it?
Can't you solve symbolically in terms of a and b, and then replace a and b by their value in the result?