AX=B,calculate complex matrix,while A and B is many dimensions - jaxb2-basics

now I calculate AX=B ,while A X B is complex matrix,if i set size A is 3*3,B is 3*1,and it Calculate the correct.But if i set A is 58*58 and B is 58*256 complex matrix,it Calculation error.And i see the error happen at cublasCgemv,.I see the L have value,and d_B have value also,after cublasCgemv,there is no value ,

Related

Finding three functions that interpolates between equitation

For a past week I been trying to construct specific functions that would satisfy some the requirements, sadly it was not successful. I decided to give a shot in stack overflow.
I have three shapes in 2D world as shown in the image. Shape A with center a, Shape B with center b and shape C with center c. For this problem shape form does not matter so I will not expand on that. Other important variables are d_ab with represents minimum distance between shape A and B, d_bc - distance between B and C, d_ac - distance between A and C. Also d_ab, d_bc, d_ac ranges from 0 to 1, where 1 represents shapes are touching and 0 their too far from specific threshold.
Here is the image of it
I am trying to find three new functions:
f_a(d_ab, d_bc, d_ac) = x
f_b(d_ab, d_bc, d_ac) = y
f_c(d_ab, d_bc, d_ac) = z
Firstly, these functions with inputs d_ab, d_bc, d_ac in the left side table should result to values x, y, z right side table:
d_ab
d_bc
d_ac
x
y
z
1
0
0
(a+b)/2
(a+b)/2
c
0
1
0
a
(b+c)/2
(b+c)/2
0
0
1
(a+c)/2
b
(a+c)/2
1
1
1
(a+b+c)/3
(a+b+c)/3
(a+b+c)/3
0
0
0
a
b
c
Secondly, all other inputs d_ab, d_bc, d_ac that are not described in table (From 0 to 1) should result in interpolated values between closest ensuring continuity (Continuity I am referring there is that small change in input should not produce big difference in output, there is probably better way to describe this mathematically).
For example:
f_a(0.3, 0, 0) = x
Most likely will combine equitation's from table:
f_a(0, 0, 0) = a
f_a(1, 0, 0) = (a+b)/2
Resulting into:
f_a(0.3, 0, 0) = 0.7 * a + 0.3 * (a+b)/2
I am curious is there a method to find these kind of functions, I assume there could be more than one that satisfies this requirement. But I am fine with any of it as long it has that continuity that I referred above.
I almost sure there is better way to represent this problem mathematically, but I am not that great with it.

Getting SUM of MySQL table data when there is floating point numbers

I an using MySQL database and I have a table called fertilizer_storage which is using both plus and minus values. It has 4 columns uria,TSP,MOP and TDM
I am using double as data type and getting sum of each column using follwing syntax,
SELECT SUM(uria),SUM(TSP),SUM(MOP),SUM(TDM) FROM `fertilizer_storage` WHERE `branch_ID`=1
The problem is for some columns I get unwanted floating points of 15 while all columns are containing numbers up to 4 floating points.
7.666900000000002
7.666900000000002
9.6109
9.9924
when I changed numbers in first two columns as other two it gives the correct answer. what should I do to correct this.
You can use ROUND(X, D):
Rounds the argument X to D decimal places. The rounding algorithm
depends on the data type of X. D defaults to 0 if not specified. D can
be negative to cause D digits left of the decimal point of the value X
to become zero.
SELECT Round(Sum(uria), 4),
Round(Sum(tsp), 4),
Round(Sum(mop), 4),
Round(Sum(tdm), 4)
FROM `fertilizer_storage`
WHERE `branch_id` = 1
See it in action

A simple vote aggregation function

I want to evaluate the acceptance rate of a proposal, where a proposal can receive two types of votes: namely positive and negative.
So the simplest function that comes to mind is as follows:
p + n / p + n + \epsilon
However I would like to come up with a more sophisticated function which would satisfy the following two properties.
The ratio of positive votes to the total amount of votes should always take precedence. So where p1 = 5, n1 = 0, p2 = 99, n2 = 1 the function should calculate a higher acceptance rate for the first one.
When the ratios are equal, the function should return a higher acceptance rate for the one with the higher number of total votes. So in the following case where p1 = 1000, n1 = 0, p2 = 10, n2 = 0 again the first one should have a higher acceptance rate.
Another idea concerning the function could be the following:
w * [p / (p + n)] + (1 - w) * [(p + n) / maxV]
where maxV is the maximum number of votes that any proposal received and w is a real number in [0..1].
This function satisfy the second condition whereas the guarantee does not extend to the first one. Finding a value for w to satisfy the system could be cumbersome thus I'm searching for a better solution.

Comparing two numbers that are approximately equal

I have two tables, Table A and Table B. I have two attributes L1 and L2 for each table. I am trying output all the rows for both tables where L1 and L2 are equal for both tables. The problem is that L1 an L2 may differ my some small quantity. So when I run:
SELECT * FROM TableA l1 join TableB l2 on l1.L1 =l2.L1 and l1.L2 = l2.L2
I get an empty set even though there are records that do match. How do I resolve this problem?
Example:
L1 = 118.4363 for Table A but for Table B L1 = 118.445428
Instead of checking for equality, check that the difference is below some threshold (e.g., 0.1, as in the example below).
SELECT * FROM
TableA l1, TableB l2
WHERE
ABS(l1.L1-l2.L1) < 0.1
AND
ABS(l1.L2-l2.L2) < 0.1
You will need to devise some tolerance, like say a difference of 0.01. Then compute the absolute value of the two when subtracted and see if it's within your tolerance
SET #tolerance_value = 0.01;
SELECT *
FROM
TableA l1 join
TableB l2
on ABS(l1.L1 - l2.L1) < #tolerance_value and ABS(l1.L2 - l2.L2) < #tolerance_value;
You cannot ask the engine to return the ones which differ in "some small quantity".
You can choose the rows which difference "abs(a - b)" is between two fixed values.
Like rows where a-b > 5 or a - b > x and a - b < x+10. for example
Try using the round function in Sybase or SQL Server so 118 matches 118. For other DBMS find a round equivalent.
mike
In order to #cheeken's answer to work, you must put a semicolon at the last query, otherwise it won't work:
SELECT * FROM
TableA l1, TableB l2
WHERE
ABS(l1.L1-l2.L1) < 0.1
AND
ABS(l1.L2-l2.L2) < 0.1;

A homework about growth rate of function

Please order the function belows by growth rate
n ^ 1.5
n ^ 0.5 + log n
n log ^ 2 n
n log ( n ^ 2 )
n log log n
n ^ 2 + log n
n log n
n
ps:
Ordering by growth rate means, as n gets larger and larger, which function will eventually be higher in value than the others.
ps2. I have ordered most of the functions:
n , n log log n, n log n, n log^2 n, n log ( n ^ 2 ), n ^ 1.5
I just do not know how to order:
n ^ 2 + log n,
n ^ 0.5 + log n,
these 2 values
Can anyone help me?
Thank you
You can figure this out fairly easily by graphing the functions and seeing which ones get larger (find a graphing calculator, check out Maxima, or try graphing the functions on Wolfram Alpha). Or, or course, you just pick some large value of n and compare the various functions, but graphs can give a bit of a better picture.
The key to the answer you seek is that when you sum two functions, their combined "growth rate" is going to be exactly that of the one with the higher growth rate of the two. So, you now know the growth rates of these two functions, since you appear (from knowing the correct ordering of all the others) to know the proper ordering of the growth rates that are in play here.
Plugging in a large number is not the correct way to approach this!
Since you have the order of growth, then you can use the following rules http://faculty.ksu.edu.sa/Alsalih/CSC311_10_11_01/3.3_GrowthofFunctionsAndAsymptoticNotations.pdf
In all of those cases, you're dealing with pairs of functions that themselves have different growth rates.
With that in mind, only the larger one really matters, since it will be most dominant even with a sum. So in each of those function sums, which is the bigger one and how does it compare to the other ones on your larger list?
If you need to proof mathematically, you should try something like this.
If you have two functions, e.g.:
f1(n) = n log n
f2(n) = n
You can simply find the limit of f3(n) = f1(n)/f2(n) when n tends to infinity.
If the result is zero, then f2(n) has a greater growth rate than f1(n).
On the other hand, if the result is infinity then f1(n) has a greater growth rate than f2(n).
n0.5 (or n1/2) is the square root of n. So, it grows more slowly than n2.
let say n = 4 then we get
n ^ 2 + log n = 16.6020599913
n ^ 1.5 = 8
n = 4
n log ( n ^ 2 ) = 4.81
n ^ 0.5 + log n = 2.60205999133
n log n = 2.4
n log ^ 2 n = ?
n log log n = -0.8