I am not used to using Maple, so this question may be fairly basic.
However, I cannot find anything helpful on the internet.
I am currently using Maple 13.
I need to draw the graph or find the solution of the following function:
f(x)=arccos(cos((1/273)*(2*Pi*10)*t)*cos(2*Pi*t*(1/365))+cos(6*Pi*(1/180))*sin((1/273)*(2*Pi*t*10))*sin(2*Pi*t*(1/365)))
And using the "plot" method in Maple, I tried to draw the graph, and as you can see, the function is periodic, so I expected the graph to be so. However, the graph was not periodic at all.
Also, using the "fsolve" method, I tried to find the root of the equations, only to find out the disappointing result: "0.", the most trivial solution of all.
I figured out that the reason for the error might be in the function itself, or maybe it's just the floating point representation, since no computer code can handle an irrational number exactly.
Is there any way to handle the numbers and/or the sin, cos, arccos functions more accurate to make the outcome get better?
Related
I'm making a program that implements procedural content generation (PCG) to create maps in a 2d game.
I use the graph data structure as the basis. then the graph will be transformed into a map like in the example image I attached.
with graph specifications as follows:
-vertex can have more than 4 edges
-allowed the formation of cycles in the graph
any suggestions on what method I can use to transform the graph to a 2d map in a grid with space-tight results?
thanks
Uh, that is a tough one. The first problem you will encounter is whether this is even possible for the graph you use. See more below for that specific topic.
Let's say we ignore the fact that your graph could be impossible to map to a grid. I faced the same issue in my Master's Thesis a few years back. (PDF available here; 3.4 World Generation; page 25). I tried to find an algorithm, that could generate my world from a graph structure but ultimately failed. I tried placing one element after the other and implemented some backtracking in case it got stuck. But in the end you're facing a similar complexity to calculating chess moves. At some point you know you messed up, but you don't know how many steps you should go back/reverse, before trying the next one. If you try to solve this by brute force, you're not going to have a good time. And I did not come up with good heuristics to solve it in an adequate time.
My solution: I decided in the end to go with AnswerSet Programming. You're basically not solving the problem with an algorithm, but you find a (more or less) elegant logical representation of your problem and let a logic solver (program specifically made to find a valid solution to your logical problem-representation) do the work. Have a look in my thesis about the details, it was a few years ago and I didn't use one since. I remember however, that this process was not easy and it took me a few days to find a good logical representation of my problem.
Another question to ask: Could you work on the grid directly? Or maybe on a graph structure representing a grid? In the end a grid is nothing else than a graph; every cell is a node and neighbouring connections are the edges. I have quite some experience in the field and would be happy to help you, if you'd like to share what you want to achieve with your generator. I have also a vast collection of resources about procedural generation, maybe you find something helpful there, too.
More on the planarity of a graph: For your graph to be mappable to a plane, it needs to be planar, and checking so is also not trivial. The easiest way - if I'm not mistaken - is to prove the existence of a non-planar sub-graph, e.g. the K5 (the smallest non-planar a complete graph) or K3,3 (the smallest non-planar complete bipartite graph). And even if your graph is planar, it is not necessarily guaranteed that you can put it on your grid.
I am trying to solve a numerical equation in R but would want a method which perform similar to vpasolve in Matlab. I have a non linear equation (involving lot of log functions) which when solve in R with uniroot gives me complete different answer compared to what vpasolve gives in matlab.
First, a word of caution: it's often much more productive to learn that there's a better way to do something than the way you are used to doing.
edit
I went back to MATLAB and realized that the "vpa" collection is using extended precision. Is that absolutely necessary for your purposes? If not, then my suggestions below may suffice.
If you do require extended precision, then perhaps Rmpfr::unirootR function will suffice. I would like to point out that, since all these solvers are generating an approximate solution (as opposed to analytic), the use of extended precision operations seems a bit pointless.
Next, you need to determine whether MATLAB::vpasolve or uniroot is getting you the correct answer. Or maybe you simply are converging to a root that's not the one you want, in which case you need to read up on setting limits on the starting conditions or the search region.
Finally, in addition to uniroot, I recommend you learn to use the R packages BBsolve , nleqslv, rootsolve, and ktsolve (disclaimer: I am the owner and maintainer of ktsolve). These packages are pretty flexible and may lead you to better solutions to your original problem.
As far as I understand R's nonlinear equation solver nleqslv(x, fn) finds only one solution of the nonlinear equation.
However (as Bhas commented) searchZeros function (the same package) can find my solutions depending on the starting points.
Question: are there some function in R which can help choosing the set of initial points for searchZeros ,which will help me to find all the solutions ?
I am interested in the case of function with several variables.
I undestand that solution to be found pretty much depends on the initial approximation. So the brute force way is to check some reasonable grid of intial approximations. However there might be some more intelligent way to get all the solutions ?
I need to find a way to handle extremely small numbers in R, particularly in order to take the log of extremely small numbers. According to the R-manual, “on a typical R platform the smallest positive double is about 5e-324.” Well, I need to deal with numbers even smaller (at least as small as 10^-350). If R is incapable of doing this, I was wondering if there is a way I can use a program that can do this (such as Matlab or Mathematica) from R.
Specifically, I am computing a matrix of probabilities, and some of these probabilities are so small that R does not distinguish them from 0. The reason I know this is because each probability is the product of two other probabilities; so I’ll have p(x)=10^-300, p(y)=10^-50, and then p(x)*p(y)=0. I’d like to be able to do these computations, take the log of the resultant very small number (-805.905 for my example, according to Mathematica), and then continue working with the log values in R.
So to be more detailed, I have a matrix of values for p(x), a matrix of values for p(y), both computed using dnorm, and I’m computing the product. In many cases, R is capable of evaluating p(x) and p(y), but the p(x)*p(y) is too small. In a few cases, though, even the p(x) or p(y) value itself is too small, and is itself just equated to 0 in R.
I’ve seen that there is stuff out there for calling R from Mathematica, but not much pertaining to calling Mathematica from R. I’d honestly prefer to do the latter than the former here. So if any one either knows how to do this (either employing Mathematica or Matlab or something else in R) or has another solution to this issue, I’d greatly appreciate it.
Note that I realize there are a few other threads on this topic, discussing such things as using the Brobdingnag package to deal with small numbers, but these do not appear applicable here.
I'm writing an javascript applet make it easy for others to see how a system with and without proportional controller works and what the outputs are.
First a little explanation on the applet (You can skip this if you want, the real question is in the last paragraph.):
I managed to implement a way of input for the system (in the frequency domain), so the applet can do the math and show the users their provided system. At the moment the applet computes the poles and zeros of the system, plots them together with the root-Loci, plot the Nyquist curve of the system and plot the Bode plots of the system.
The next thing I want the applet to do is calculating and plotting the impulse response. To do so I need to perform an inverse Laplace transformation on the transferfunction of the system.
Now the real question:
I have a function (the transferfunction) in the frequency domain. The function is a rational function, stored in the program as two polynomes (numerator and denominator stored by their coefficients). What would be the best way of transforming this function to the time domain? (inverse Laplace). Or is there an open-source library which implements this already. I've searched for it already but only found some math libraries for with more simple mathematics.
Thanks in advance
This is a fairly complex and interesting problem. A couple of ideas.
(1) If the solution must be strictly JS: the inverse LT of some rational functions can be found via partial fraction decomposition. You have numerical coefficients for the polynomials, right? You can try implementing a partial fraction decomposition in JS or maybe find one. The difficulty here is that it is not guaranteed that you can find the inverse LT via partial fractions.
(2) Use JS as glue code and send the rational function to another process (running e.g. Sympy or Maxima) to compute the inverse LT. That way you can take advantage of all the functions available, but it will take some work to connect to the other process and parse the result. For Maxima at least, there have been many projects which use Maxima as the computational back-end; see: http://maxima.sourceforge.net/relatedprojects.html
Problem is solved now. After checking out some numerical methods I went for the partial fraction decomposition by using the poles of the system and the least square method to calculate the coeficients. After this the inverse LT wasn't that hard to find.
Thx for your suggestions ;)
Ask me if you want to look at the code.