Maple: Find intersection of two functions - intersection

I have a Maple worksheet like this:
And have been unable to figure out how to find the intersection of the two, as fsolve returns an error?

Note that f is a function and g is an equation. And you want to solve f(x)=y, not f(x)=0. So your fsolve command should be
fsolve({f(x)=y, g}, {x,y}, x= -2..-1);
By changing the x-range, you can get all three intersection points this way. There is no need to give a y-range.

Related

Octave: How to solve a one order differential equation with variable coefficients

I'm trying to solve a one order differential equation with variable coefficients of the following form:
xdot(1)=a(t)*x(1)+b;
where b=a constant and where a(t) = a time dependent function. I know that I can solve this equation by hand butt a(t) is a quite complex function.
So, my problem is the following. a(t) is a function which I know its values from an experiment (I've got all the results in a file) --> a(t) is a vector (n x 1) which is a problem because x(1)= xdot(1)=a scalar. So, how could I solve this equation, with lsode ?
Possibly I have underestimated your problem, but the way I read it, you are asking to integrate a first order ODE. In general there are two ways to proceed,, implicit methods and explicit methods. Here is the crudest, but easiest to understand, method I can come up with:
nt=101;a=-ones(1,nt);b=1/2;x=NaN*ones(1,nt);x(1)=pi;dt=0.01;
for kt=2:nt
dxdt=a(kt-1)*x(kt-1)+b;
x(kt)=x(kt-1)+dxdt*dt;
endfor
plot(x)
I have assumed a<0 so there is no tendency to blow up. You will want to set it equal to your observed values.

Mysql: ST_Contains with borders to detect if multipolygon contains point

I use mysql spatial functions.
I have to understand if points lies withing multipolygon.
Initially I used MBRContains but it works in a strange way, so I faced the following error: Mysql function MBRContains is not accurate
My next step was switching to the functions ST_Contains. But I found out that if I use polygon(from multipolygon) vertex as argument - function returns false but I want to unclude all multipolygon borders.
P.S.
I found that where are function:
ST_Touches(g1, g2)
Two geometries spatially touch if their interiors do not intersect,
but the boundary of one of the geometries intersects either the
boundary or the interior of the other
Looks like it works like I want(in OR conditions with ST_contains) but documentation is not clear for me. Can you explain how can 2 conditions be truth together
1. Interiors do not intersects
2. Boundary intersects the interrior.
?
Question:
How can I achieve the behaviour I want?
This looks like a working solution:
ST_Contains(g1,g2) || ST_Touches(g1, g2)
Looks like ST_Distance(AREA, #point)) = 0 includes border

How can I solve this kind of equation in Maple?

equation1:
solve({a^2+b^2+169+sqrt(c-13)-24*a-10*b = 0},{a, b, c})
assuming a>0, b>0, c>0;
//a=12, b=5, c=13
equation2:
solve([1/(cos(a)^2)+1/(sin(a)^2*sin(b)^2*cos(b)^2) = 9,
a>0, a<Pi/2, b>0, b<Pi/2], [a,b,c] );
//a=arctan(sqrt(2)), b=Pi/4
I have tired above, but maple couldn't gives a solutions, Am I using solve incorrectly?
In (Eq. 1) it's not your syntax that's an issue. You have three unknowns {a,b,c} but only one equation. You simply do not have enough equations to determine {a,b,c} uniquely. Maple's solve function only returns an answer (if possible) if the number of variables equals the number of equations.
In (Eq. 2) you use square brackets, which are used for ordered lists. The solve function requires a set of equations, which are indicated by curly braces. Again, you have three variables but only one equation. Same problem.
If the equations are linear (which they aren't in your case), Maple can find a parameterization for the solutions in the case of an underdetermined system: http://www.maplesoft.com/support/help/Maple/view.aspx?path=solve/linear.

matlab function which is a function of an intergral

I need to write my own function which has the form f(x,y)=Integrate(g(x,y,z),z from 0 to inf). so the code I used was:
function y=f(x,y)
g=#(z)exp(-z.^2)./(z.^x).*(z.^2+y.^2).^(x/2);% as a function of x,y and z
y=quadgk(g,0,inf)
and if I call it for a single value like f(x0,y0), it works but if I try to calculate something like f([1:10],y0), then the error message says that there is something wrong with the times and dimension. In principle I can use for loops but then my code slows down and takes forever. Is there any help I can get from you guys? or references?
I'm trying to avoid the for loop since in matlab it's much faster to use matrix computation than to use for loop. I wonder if there is any trick that I can take advantage of this feature.
Thanks for any help in advance,
Lynn
Perhaps you can try to transpose the interval, creating row based values instead of column based f([1:10]',y0). Otherwise something in your function might be wrong, for example to get x^y to work with lists as input, you have to prefix with a dot x.^y. The same for mulitply and division I think..
If loop is no problem for you, you should do something like:
function y2=f(x,y)
y2=zeros(size(x));
for n=1:numel(x)
g=#(z)exp(-z.^2)./(z.^x(n)).*(z.^2+y.^2).^(x(n)/2);% as a function of x,y and z
y2(n)=quadgk(g,0,inf)
end
The problem here is that quadk itself uses vectors as argument for g. Then you have in g somethink like z.^x, which is the power of two vectors that is only defined if z and x have the same dimension. But this is not what you want.
I assume that you want to evaluate the function for all arguments in x and that the output vector has the same dimension as x. But this does not seem to be possible since even this simple example
g=#(x)[x;x.^2]
quad(g,0,1)
does not work:
Error using quad (line 79)
The integrand function must return an output vector of the same length as the
input vector.
A similar error shows when using quadgk. The documentation also says that this routine works only for scalar functions and this is not surprising since an adaptive quadrature rule would in general use different points for each function to evaluate the integral.
You have to use quadvinstead, which can integrate vector valued functions. But this gives wrong results since your function is integrated in the interval [0,\infty).

Matlab: how to apply point-wise function on a matrix?

I am using Matlab to do one of my projects. I am stuck at one basic thing.
I have 2 matricies - A and B and a vector V. What I want to do is this:
A(i, j) = V(B(i,j)) for all i, j.
I tried doing this in the most obvious way - nested loops. For some reason, A is not getting populated. Am I missing something? Is there a more efficient (in-built function) way of doing this.
Thanks,
Anil.
If all entries in B are integers larger than zero, and if the maximum of B is not larger than the number of elements in V, then you can simply write
A = V(B);