diff function doesn't work with Greek letters - symbolic-math

Consider the list
P : [r * sin(%phi) * sin(%gamma), r * cos(%phi), r * sin(%phi) * cos(%gamma)];
when using the diff() function:
diff(P, %phi, 1);
and I get the error:
diff: second argument must be a variable; found 𝜑
-- an error. To debug this try: debugmode(true);
Now if I remove the % percent sign before the Greek letters
P : [r * sin(phi) * sin(gamma), r * cos(phi), r * sin(phi) * cos(gamma)];
it works but it shows some Greek symbols as their capital:
I would appreciate if you could help me know what is the problem and how I can solve it. Thanks for your support in advance.

Related

How to do SUM on array from outside file?

I'm newbie college student for programming studies,
so recently i have task to calculate matrix from outside files for Gauss Jordan Numeric Method, in the txt file i provide has 10 (x) and (y) data, and declare with do functions to calculate the 10 data from the txt file each for x^2, x^3, x^4, xy, x^2y
my question is : how to SUM (calculate total) each x^2, x^3 ... that was calculated by program ? i try do sum file in below and still got errors (the first argument of sum must not a scalar.)
the Fortran apps i use was Plato cc from Silverfrost.
I apologize if my english bad and my pogram looks funny.
i have 10 data in my txt looks like these :
(x) (y)
12 10
5 6
28 8
9 11
20 17
6 24
32 9
2 7
1 30
26 22
in program below i open these files and want each x and y i provide read and calculate to get x^2, x^3, x^4, xy, x^2y
Program Gauss_Jordan
Real x(10),y(10),xj,yj,xj2,xj3,xj4,xjyj,xj2yj
Open (10, file='Data.txt')
Do j = 1,10
Read(10,*) x(j), y(j)
xj2 = x(j)**2
xj3 = x(j)**3
xj4 = x(j)**4
xjyj = x(j)*y(j)
xj2yj = (x(j)**2)*y(j)
Do k = 1,10
T(xj2) = SUM( xj2, dim=1)
T(xj3) = SUM (xj3, dim=1)
T(xj4) = SUM (xj4, dim=1)
T(xjyj) = SUM (xjyj, dim=1)
T(xj2yj) = SUM (xj2yj, dim=1)
End Do
End Do
Close(10)
End
for T(xj2) I want to get one result scalar result from SUM the all xj^2 that program has been calculated.
Like in excel was expected :
(A) is 1st xj^2 value that has been calculated
.
.
.
until (J) is 10th xj^2 value that has been calculated
sxj^2 = SUM(Xj^2)
SUM (A-J)
The 'sum' intrinsic needs an array argument, which we can compute from the input arrays without using a loop, so your program could be:
Program Gauss_Jordan
Real x(10), y(10), x2(10), x3(10), x4(10), xy(10), x2y(10)
Open(10, file='Data.txt')
Do j = 1, 10
Read (10, *) x(j), y(j)
End Do
Close(10)
x2 = x**2
x3 = x**3
x4 = x**4
xy = x*y
x2y = (x**2)*y
sx2 = SUM(x2)
sx3 = SUM(x3)
sx4 = SUM(x4)
sxy = SUM(xy)
sx2y = SUM(x2y)
End
From what I see I think you are misunderstanding what the SUM intrinsic does. Since your example isn't storing xj2, xj3 etc. in arrays, SUM isn't going to be useful to you. Instead you could declare totals as scalars (as you described you wanted) and simply add the individual xj2 variables in a loop as in the example below.
Also, you should get in the habit of using the implicit none declaration. It will save you from unexpected errors due to spelling mistakes.
Program Gauss_Jordan
implicit none
Real x(10),y(10),xj,yj,xj2,xj3,xj4,xjyj,xj2yj
real :: Txj2,Txj3,Txj4,Txjyj,Txj2yj
integer :: j
Txj2 = 0
Txj3 = 0
Txj4 = 0
Txjyj= 0
Txj2yj= 0
Open (10, file='Data.txt')
Do j = 1,10
Read(10,*) x(j), y(j)
xj2 = x(j)**2
xj3 = x(j)**3
xj4 = x(j)**4
xjyj = x(j)*y(j)
xj2yj = (x(j)**2)*y(j)
Txj2 = Txj2 + xj2
Txj3 = Txj3 + xj3
Txj4 = Txj4 + xj4
Txjyj = Txjyj + xjyj
Txj2yj = Txj2yj + xj2yj
End Do
print *, 'Txj2 = ', Txj2
Close(10)
End
When I ran this I got the output below which is what I believe you intended:
3175

what are all the operations that FFMPEG uses to convert from yuv420p to rgb bmp?

I am trying to replicate in my own code, not using ffmpeg libraries, the operations that ffmpeg does to convert yuv420p to rgb. Initially I thought it would be inside the function: xyz12Torgb48 in swscale.c but doing some tracing , it looks to be in yuv2rgb.c ff_yuv2rgb_c_init_tables, which I can not quite see it.
well, since nobody came out with a solution , I am just gonna post that I found using
valgrind tool=callgrind ffmpeg_g
which is a version of ffmpeg with debug objects that showed me the functions being called and inside \libswscale\x86 there is yuv2rgb_template.c which seems to have the operations you do yuv2rgb , in assembly
* Conversion is performed in usual way:
* R = Y' * Ycoef + Vred * V'
* G = Y' * Ycoef + Vgreen * V' + Ugreen * U'
* B = Y' * Ycoef + Ublue * U'
*
* where X' = X * 8 - Xoffset (multiplication is performed to increase
* precision a bit).
* Since it operates in YUV420 colorspace, Y component is additionally
* split into Y1 and Y2 for even and odd pixels.
*
* Input:
* mm0 - U (4 elems), mm1 - V (4 elems), mm6 - Y (8 elems), mm4 - zero register
* Output:
* mm1 - R, mm2 - G, mm0 - B
*/ ```

Problems with Expressions in C

I have two functions written that have simple assignment statements with very simple expressions. The expressions are the same for both functions, however, they involve different variable types: One function uses an array of structs, the other just uses a typedef'd struct.
When running the functions, the second function fails to divide by 256, and I get very high values that are not "normalized". I have to uncomment the second line in the second function (valueB = valueB / 256) to get it to work.
The first function, however, works perfectly.
Heres the statement in Function One:
value = ((p[0].value * p2Area)+(p[1].value * p3Area)+(p[2].value * p0Area)+(p[3].value * p1Area) / 256);
Heres the statement in Function Two:
valueB = ((dataPoints.p0B * p2Area)+(dataPoints.p1B * p3Area)+(dataPoints.p2B * p0Area)+(dataPoints.p3B * p1Area) / 256);
//valueB = valueB / 256;
Why would this happen?
Also, I pass the functions the same numbers and it doesn't seem to help.
This is on MacOSX 10.6.8, inside Xcode 3.2.6
Are you absolutely sure the first one works properly? You have
value = ((p[0].value * p2Area)+(p[1].value * p3Area)+(p[2].value * p0Area)+(p[3].value * p1Area) / 256);
I think you want:
value = (((p[0].value * p2Area)+(p[1].value * p3Area)+(p[2].value * p0Area)+(p[3].value * p1Area)) / 256);
Similar thing with the second. I think it should be:
value = (((p[0].value * p2Area)+(p[1].value * p3Area)+(p[2].value * p0Area)+(p[3].value * p1Area)) / 256);
In both cases I think you want to divide the sum of the products by 256. Not just the last one. My change only involves placing an extra set of parentheses around the sum of the product subexpressions and dividing the entire thing by 256
In all languages there is an order by which mathematical (and all other operators are completed). It just so happens that * and / are higher in precedence than + and - in C/C++ You may refer to this link for more details.
To simplify what happened to you, I will create this simple equation:
2 + 4 + 6 + 4 / 2
Since division occurs first (and there are no parentheses to alter the order) it gets computed as:
2 + 4 + 6 + (4 / 2) = 14
Not:
(2 + 4 + 6 + 4) / 2 = 8
So my change to your code was the same as putting parentheses around 2 + 4 + 6 + 4 / 2 giving (2 + 4 + 6 + 4) / 2 and forcing the division to be done last after all the additions are completed.

Convert an array of timestamps to seconds in Matlab

I'm new to SO and Matlab so please excuse any transgressions.
I'm trying to convert a seemingly simple array of timestamp strings to an equivalent array of seconds.
I wrote a this function:
% Function to calculate seconds from a timestamp in the following format:
% ddd hh:mm:ss.SSSS (example: 123 12:59:00.9999)
function a = TimestampToS(stamp)
% Uses the "named tokens" facility of MATLAB's "regexp" function.
expr = ['(?<ddd>\d+)' ... % ddd
' ' ... % Space " " separator
'(?<hh>\d+)' ... % hh
':' ... % Colon ":" separator
'(?<mm>\d+)' ... % mm
':' ... % Colon ":" separator
'(?<ss>\d+)' ... % ss
'.' ... % Dot "." separator
'(?<SSSS>\d+)']; % SSSS
parsedStamp = regexp(stamp, expr, 'names');
a = (str2double(parsedStamp.ddd) * 86400) + ...
(str2double(parsedStamp.hh) * 3600) + ...
(str2double(parsedStamp.mm) * 60) + ...
(str2double(parsedStamp.ss)) + ...
(str2double(parsedStamp.SSSS) * 0.0001);
It works great for an individual string:
>> TimestamptoS('123 12:59:00.9999')
ans =
1.067394099990000e+007
But if I try to use a cell array I get:
Attempt to reference field of non-structure array.
How can I get an array of seconds? I have tried all kinds of conversions of the input data and "parsedStamp" but nothing works. I don't understand Matlab or its matrix notation well enough. Any help gratefully received!
PS This is not a regexp question, no replies about regexp please!
You can do it very easily without modifying your function, by using cellfun. This essentially extracts each cell of the cell array and passes it to your function.
>> cellArray = {'123 12:59:00.9999','130 12:59:00.9999'}; % for example
>> cellfun(#TimestampToS,cellArray)
ans =
1.0e+007 *
1.067394099990000 1.127874099990000

SQL Server calculation returning 0 instead of a float value

I am trying to do the following operation in SQL to calculate the weighted rating :
SELECT CTE_3.idProduct,(CTE_3.vote_count / (CTE_3.vote_count + #minimumVotesRequired)) * CTE_3.vote_mean + (#minimumVotesRequired / (CTE_3.vote_count+ #minimumVotesRequired)) * ((SUM(CTE_3.vote_mean)/COUNT(CTE_3.IdProduct))) AS WeightedRating
FROM CTE_3
GROUP BY CTE_3.IdProduct,
CTE_3.vote_count,
CTE_3.vote_mean
ORDER BY idProduct;
But the problem I am facing is that the result is ALWAYS 0.. I tried using Convert(FLOAT,operation) AS WeightedRating but still I am getting a result of 0.
When I manually perform this on a calculator it returns 2.5416666..so I am quite sure that SQL Server is not being able to manage the values I feed to the operation.
Should I do something else than cast?
The values are :
vote_count is 2
vote_mean is 2.5
#minimumVotesRequired is 1
EDIT :
Now the only value after casting everything to float is 2.5 from CTE_3.vote_mean
SELECT CTE_3.idProduct,(CONVERT(FLOAT,CTE_3.vote_count) / (CONVERT(FLOAT,CTE_3.vote_count) + #minimumVotesRequired))
* CONVERT(FLOAT,CTE_3.vote_mean) +
(#minimumVotesRequired / (CONVERT(FLOAT,CTE_3.vote_count)+ #minimumVotesRequired))
* (SUM(CONVERT(FLOAT,CTE_3.vote_mean)))/COUNT(CTE_3.IdProduct)) AS WeightedRating
FROM CTE_3
GROUP BY CTE_3.IdProduct,
CTE_3.vote_count,
CTE_3.vote_mean
ORDER BY idProduct;
Any suggestion in what am I missing?
If CTE_3.vote_count type is int or #minimumVotesRequired type is int, then you are getting the truncated int value. Make sure those are floats, or cast them as floats before doing your division.
Also, don't forget that COUNT is an integer function. You will want to cast the result of your COUNT as a float as well.

Resources