I am making a program that calculates trajectory but when running the code the answer to the equation is far to small but when the same is run on a calculator the answer is fine.
so far I have tried every thing I can think of such as using the fraction module to try and resolve it:
The equation:
D= 9.81/V^2*sin(2*angle)
The python equation:
D=9.81/((200**2)*math.sin(2*10))
The target answer is 708
The current answer 0.00026836.....
Try it this way:
angle = 10*math.pi/180.0
D=9.81/((200**2)*math.sin(2*angle))
Python, like C, C++, Java, and JavaScript, uses radians for trig functions, not degrees.
Related
I currently have an issue with a new project, because I need a solution for a LCP. I know there are
algorithms like Lemke etc. But each of them seems to be written in C++ or Python(using numpy).
I am not really able to implement an algorithm by myself, because I'm not completely familiar with all the math behind it.
So my question is if there is any LCP solver for Java which I can just use by calling something like
SolveLCP(Matrix M, Vector q, Vector w, Vector z)
for computing w and z from M and q ?
I found an algorithm at
https://www.geometrictools.com/GTE/Mathematics/LCPSolver.h
which seems to work pretty good, but unfortunately it's C++ and I failed to convert it into java(actually I use kotlin). My version has the correct results sometimes, but not every time compared with the C++ implementation.
I implemented it in kotlin, you can find it here:
https://github.com/mihisg/LCPSolver_Kotlin/tree/main
I would really appreciate it if someone could help finding the errors. I think I did something wrong with representing all those pointers, but in fact, it only works sometimes.
I was wondering if there was a function in Lapack for orthonormalizing the columns of a very tall and skinny matrix. A similar previous question asked this question, presumably in the context of a square matrix. My setting is as follows: I have an M by N matrix A that I am trying to orthonormalize the columns of.
So, my first thought was to do a qr decomposition. The functions for doing a qr decomposition in Lapack seem to be dgeqrf and dormqr. Great. However, my problem is as follows: my matrix A is so tall, that I don't want to actually compute all of Q, because it is M by M. In fact, I can't afford to instantiate an M by M matrix at all during any of my computation (it would not fit in memory). I would rather compute just the matrix that wikipedia calls Q1. However, I can't seem to find a way to make this work.
The weird thing is, that I think it is possible. Numpy, in particular, has a function numpy.linalg.qr that appears to do just this. However, even after reading their source code, I can't figure out how they are using lapack calls to get this to work.
Do folks have ideas? I would strongly prefer this to only use lapack functions because I am hoping to port this code to CuSOLVE, which has implemented several lapack functions (including dgeqrf and dormqr) for the GPU.
You want the "thin" or "economy size" version of QR. In matlab, you can do this with:
[Q,R] = qr(A,0);
I haven't used Lapack directly, but I would imagine there's a corresponding call there. It appears that you can do this in python with:
numpy.linalg.qr(a, mode='reduced')
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?
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.
I am doing matrix operations on large matrices in my C++ program. I need to verify the results that I get, I used to use WolframAlpha for the task up until now. But my inputs are very large now, and the web interface does NOT accept such large values (textfield is limited).
I am looking for a better solution to quickly cross-check/do math problems.
I know there is Matlab but I have never used it and I don't know if thats what will suffice my needs and how steep the learning curve would be?
Is this the time to make the jump? or there are other solutions?
If you don't mind using python, numpy might be an option.
Apart from the license costs, MATLAB is the state of the art numerical math tool. There is octave as free open source alternative, with a similar syntax. The learning curve is for both tools absolutely smooth!
WolframAlpha is web interface to Wolfram Mathematica. The command syntax is exactly the same. If you have access to Mathematica at your university, it would be most smooth choice for you since you already have experience with WolframAlpha.
You may also try some packages to convert Mathematica commands to MATLAB:
ToMatlab
Mathematica Symbolic Toolbox for MATLAB 2.0
Let us know in more details what is your validation process. How your data look like and what commands have you used in WolframALpha? Then we can help you with MATLAB alternative.