I need to represent these mathematical equations in code and to solve them:
2x = 3y
3y = 4z
2x + 3y + 4z = 1
Please advise.
(I suspect this is homework, so I will give you some clues as to how to proceed...)
Think about how you would solve these equations on paper.
The same steps can be written into your software. Each equation has a variable and a coefficient, so you will most likely want to represent the coefficient with a variable in your program, and "solve" the equations using the same techniques you would by hand.
Perhaps this answer in SO is what you are after?
Here is a complete, documented/tutorial C# program to solve sets of linear equations: http://www.codeproject.com/KB/cs/LinearEquationsSystemSoln.aspx
By the way, C# isn't really the language for this. MATLAB or Python/scipy would have built-in solvers. See things like this: http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html
This sound like a simple case a linear algebra. Throw the equations into an M x N matrix where M is the number of coefficients + 1 and N is the number of equations.
Related
I want to implement this function to divide an angle but my math knowledge is very limited so I need help.
In practice and in programming only the lengths of the horizontal or vertical lines are available and easy to calculate.
my question is it possible to make this calculation with only one data
WZ which is horizon line
Short answer: No.
Long answer:
If XY == YZ:
bisected = arcsin(YZ/(YZ^2+WZ^2))
If XY != YZ:
bisected = 1/2*(arcsin(XY/(XY^2+WZ^2))+arcsin(YZ/(YZ^2+WZ^2)))
You'll need to know at least XZ and WZ to calculate the bisected angle.
Thanks for replying.
Yes it's easy to calculate it with the trigonomic function... since WZ is a horizontal line so by selecting any arbitrary point on WX to find the acrtan then divide it by 2
arctan(tangent of any point on WX)/2
I want to solve it with linear algebra and find the equations of the lines
Is there an algorithm to calculate average temperature by latitude? I googled for a long time but could only find this (source):
T = To – a.sin^2λ
Where
T = Temperature
To = Average equatorial temperature
a = a constant
λ = latitude.
But I have several problems with this:
There is no mentioning of a source
It's not mentioned what a is or what its value is
Is the dot between a and sin ("a.sin") meant to be a
multiplication sign?
So I was wondering if someone can explain if this algorithm is correct or if there is a better one, or none at all.
I found a confirmation for a basic relation of latitude and temperature here:
I could use a lookup table (but I would have to generate it by some algorithm anyway), but I'd rather have a realtime calculation for certain reasons.
So does anyone know if the algorithm above is correct, and can explain what the dot means?
I would like to implement this in C#, but any language with a C-like syntax would be fine for me.
Bonus question: Any chance to cover precipitation in a similar way?
Thanks in advance!
Firstly, what you've given and are looking for is more of a formula than an algorithm, while you could argue it was an algorithm, algorithms usually refer to calculations involving conditionals or separate steps, not just a single non-complex calculation.
No, there is no such formula. To have a formula for average temperature would involve simulation all of the meteorological system.
Approximations are entirely possible however and that's what the above formula is. The dot in this instance is multiplication, the * operator in c#.
It should also be noted this is not the correct stack exchange for this question, the physics stack exchange would be more appropriate.
I'm looking for a way to quickly get the results for a mathematical equation. Take "0.5 * sin(x) + 3" for example. The Google calculator can easily give me an exact result for HUGE values, but my C# application will stutter when drawing a graph in high value ranges or even give me an overflow. How do I solve this?
Thanks in advance!
I am stuck at this point. I am trying to find where two lines in graph intersects. I have 10 points for each spline, but they intersects between this points.
I am using c# graph. (System.Windows.Forms.DataVisualization.Charting.Chart chart2;)
Do you have an idea how to solve this?
Here is this situation. Points are measured manually so there is minimum posibility that it will intersetcs on this given points.
Refine the splines to the degree of precision you need and then intersect (straight) line pairs, as Matthew suggested. This can be done quite efficient if you chose the right data structure to store the line segments, so that it supports fast range queries (kd-tree perhaps?).
Doing it analytically is going to be really hard, I guess.
I found the solution, I used least squares theory and polynomial function to represent equation of curve and after that solve the equation. If anybody needs solution just write me.
I was looking for satisfactory and safe workaround to my double precision issue specified to this problem:
This program tries to find how many small circle can fit into a large circle. It fills the large circle and then culls those that intersect the large circumference. using this formula:
distance_small_pos_from_center + small_radius < big_radius
All calculations were in double, except for screen output on WinForms which takes int for coords.
The above image shows the result of the culling. You can see that it is not symmetric when it should really be because the constraint is that there must be one small circle exactly in the center. I step through the code and find that this is because some calculations yield, for example,
99.9999999 < 100
This answer C++ double precision and rounding off says we should use all the precision available, but in this case, I had to do a Math.Round(distance_small_pos_from_center + small_radius, 3) using 3 arbitarily.
The result of the culling differs very much without Math.Round. In retrospect, this is one kind of bug that is hard to detect if I had not drawn it out. Maybe I did something wrong, or didn't understand doubles as much as I thought I had.
So, anyone has solutions or tips to avoid this kind of problem?
Sorry for not beeing able to provide a complete answer to your question, but i have no time for that right now. But when you compare floats, compare them with a "tolerance" since a float is not exact.
EDIT: modified with abs() in case you don't know which is big and small, as pointed out by Hans Kesting
Ie, do something like if(abs(big_radius - distance_small_pos_from_center) < epsilon) where epsilon is your tolerance, selected with consideration to how "inexact" the floats will be in the range where you are working..
For more precise information see:
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html
http://www.cplusplus.com/forum/articles/3638/
Use System.Decimal:
http://msdn.microsoft.com/en-us/library/system.decimal.aspx