Unable to write the equation correctly as it keeps giving me the answer 0 which has to be around 0.4879602393 - equation

enter image description here
so I am new to C# and I have to write this equation but whatever I do, or however I try to break it down, I tried to just use different double names for some parts of the equation like (1 / 4) is S1 and then the rest as S2 S3 S4 S5 and add an Z1 that merges the whole equation together but I always end up with 0 so i guess the equation is just wrong but i cant see where my mistake is.
double c = 10 * (Math.PI / 180);
double Z2 = (1 / 4) - ((1 / 4) * Math.Sin(((5 / 2) * (Math.PI)) - (8 * c)));

In C#, integer division returns an integer, so 1 / 4 always returns the rounded value of zero. Try division with at least one operand a floating point value, e.g. 1.0 / 4.

Related

How do I plot this simple thing correctly in Octave?

I am a student trying to learn how to use Octave and I need help with plotting this thing right here the function I want to plot
The code looks like this:
x2 = 0:0.1:50;
y2 = power((1+(2.*x2/(exp(0.5.*x2)+(x2.^2)))), 0.5);
plot(x2, y2, '-b');
It feels like it should have plotted without problems but the plot in the figure appears to be completely empty, and I cannot wrap my head around why this might happen. Would love to know what am I doing wrong
If you inspect the value of y2 (simply type y2 and press enter) then you find that y2 is a single number rather than a vector.
To find out out why y2 is a single number we type in the calculation power((1+(2.*x2/(exp(0.5.*x2)+(x2.^2)))), 0.5) and remove the outer functions/operators step by step. Once the result is a vector we know that the last thing removed ruined the result.
In your case / turns out to be the culprit.
From Octave, Arithmetic Ops (emphasis mine):
x / y
Right division. This is conceptually equivalent to the expression (inv (y') * x')' but it is computed without forming the inverse of y'.
If the system is not square, or if the coefficient matrix is singular, a minimum norm solution is computed.
x ./ y
Element-by-element right division.
Therefore, replace / by ./.
x2 = 0:0.1:50;
y2 = power(1 + 2 .* x2 ./ (exp(0.5 .* x2) + (x2 .^ 2)), 0.5);
plot(x2, y2, '-b');

MySql POWER() large exponent - DOUBLE value is out of range

I have an issue to transfer a python calculation formula into MySQL view, Mysql Power function returns every time DOUBLE value is out of range for POWER.
Python formula
exponent = (3 - 1) * 100000
my_value = 0.9654 - 0.9650
result = my_value / 10 ** exponent
Transferred into MySQL but because the exponent is big is resulting every time in DOUBLE value is out of range for POWER
SELECT 0.9604 / POWER(10, (4 - 3) * 100000);
result in DOUBLE value is out of range for POWER
Will appreciate any help.
Thank you in advance
Eh? DOUBLE is limited to about 10 ** 308. You are asking for 10 ** 200000. It should overflow.
(The SELECT is asking for only 10**100000, but that is still too big.)
Virtually all floating point "DOUBLE" implementations in computers (at least since the late '80s) have the same limitations. More discussion: https://en.wikipedia.org/wiki/Double-precision_floating-point_format#Exponent_encoding

manipulation of equations in maxima

I searched the maxima manual about how to manipulate the equation and the likes but I can't really find it.
I've already implemented coefmatrix in terms of ratcoef and using lhs and rhs. To finish it and proceed to augmented part, I need to know how to do this.
How can I make this:
x + 10 - y = z + 5;
turn into this:
x - y - z = -5;
There are a couple of ways to do it. (1) I assume that you have already figured out how to get the coefficients via ratcoef and the right-hand side via rhs. Let foo be the right-hand side minus the left-hand side (so now you have right - left = 0. Subtract the sum of all the variables times their coefficients from that. Then the remainder is the constant part that doesn't depend on any variable. (2) Use freeof to identify terms which are free of (i.e., do not contain) any variable.

Don't reduce algebraic fractions in Maple

I would like to do some computations with partially defined functions like (x-3)^3 / (x-3). Maple automatically reduces algebraic fractions with no regard to points like x = 3. Unevaulation doesn't help much, because it's stripped before functions (i.e. solve) could ever make use of that points.
How should I work with such functions?
For your given example you could try working instead with the expanded forms of numerator (and also of denominator, for some other examples).
Ie,
nd := (n,d) -> expand(n)/expand(d):
expr := nd( (x-2)^3, x-2 );
3 2
x - 6 x + 12 x - 8
--------------------
x - 2

MySQL spatial relation query returning empty result set?

Okay, I have a reasonably complex query which checks to see if a point variable, containing a set of latitude+longitude coordinates (which I have substituted with -41.000000 & 174.000000 for readability) is contained within a polygon, which is created from my table called squares (which contains 2.25m rows of coordinates representing the top left corner of a square, which I then extrapolate out by adding 0.5 / 60 to each coordinate to create a square). It checks to see if there's a match by using the MySQL MBRContains function. The only problem is, it isn't working at all, and I simply get this message:
MySQL returned an empty result set (i.e. zero rows).
Here's the query:
SELECT `square_id` FROM `squares` WHERE
MBRContains(
GeomFromText(
CONCAT(
'POLYGON((',
`coord_lat`,' ',`coord_long`,',',
`coord_lat`,' ',(`coord_long` + (0.5 / 60)),',',
(`coord_lat` + (0.5 / 60)),' ',(`coord_long` + (0.5 / 60)),',',
(`coord_lat` + (0.5 / 60)),' ',`coord_long`,
'))'
)
),
GeomFromText('POINT(-41.000000 174.000000)')
)
Any idea why this is? There definitely is a square that contains the coordinates within my point object, and I can't see any obvious errors in my SQL syntax. Thoughts?
Two things going on here:
Vertices in WKT definitions are defined as (X,Y), unlike latitude/longitude, which is defined as "X,Y". You are building up your WKT POLYGON and POINT strings using (lat lng), but should be using (lng lat). Since you're consistent about it, this would work here, but might break in other situations.
The actual problem is the POLYGON you are creating is not closed. MySQL quietly returns a null when GeomFromText is passed an invalid WKT string, so the MBRContains doesn't find any intersections. To close the POLYGON, you need to add the start point to the end of the polygon string. Try changing your SQL to this:
SELECT `square_id` FROM `squares` WHERE
MBRContains(
GeomFromText(
CONCAT(
'POLYGON((',
`coord_lat`,' ',`coord_long`,',',
`coord_lat`,' ',(`coord_long` + (0.5 / 60)),',',
(`coord_lat` + (0.5 / 60)),' ',(`coord_long` + (0.5 / 60)),',',
(`coord_lat` + (0.5 / 60)),' ',`coord_long`,',',
`coord_lat`,' ',`coord_long`
'))'
)
),
GeomFromText('POINT(-41.000000 174.000000)')
)