Fortran double summation - sum

So, I want to do a double summation over two variables of a four-variable function, my question is: are the summations in the picture equivalent? Am I doing it right?

No, I do not think you are doing that right. Your two sums are going to be identical.
Try this:
do i=1,s
do j=1,s
prob1(i,j)=sum(prob(i,j,:,:))
prob2(i,j)=sum(prob(:,:,i,j))
end do
end do

Related

Optaplaner - Working with double variable in ConstraintProvider

Is there a way I can use groupBy(ConstraintCollectors.sum(x)) such as x is a variable of type Double ?
I don't want to round it to n decimal pointes then multiply by 10^n. I would like to use the Double variable as is.
As explained in an earlier answer, OptaPlanner does not provide means of working with double.
That said, ConstraintCollectors.sum() is simple and if you look up its implementation, you should be able to implement a double-based one easily. Use with caution.

Can you help me to solve recurrence relation T(1)=5, and for all n>=2, T(n)=2T(n-1)+(3*n+1)

T(1)=5,
and for all n>=2: T(n)=2T(n-1)+(3*n+1).
I tried to solve this problem, but I have a problem with 3*n+1. When I put n-1, n-2,..., I don't know how to determine the formula for this problem.
Since there is only (3*n+1) as term and not T(3*n+1) this is solvable. First impression: you have 2T(n-1) as subterm, so the solution is something like 2^n.
Through a simple Excel data analysis I found the solution T(n)=-7-3n+15 * 2^(n-1), I will try to solve it per hand and will update my answer if I found the right path.
Edit: This was more difficult than expected...
Explanation:
first step is to get a sum formula for n. You can derive this pattern from the first few T(n).
Once you get the pattern, try to get rid of the sum.
To solve sums, try to get them in a similar format as sum_(i=1)^n (1) = n or sum_(i=0)^n (2^i) = 2^(n+1)-1
to do this you can manipulate the index such as sum_(i=2)^n (n-i) = sum_(i=0)^(n-2) (i) or to include/exclude elements from the sum.
the trickiest part was to solve sum_(i=0)^n ((n-i)*(2^i)). The idea here is to convert the multiplication (depending on i) to a sum (also depending on i).
please note the changing indice-numbers. sum_(i=0)^n (2^i) is not the same as sum_(i=1)^n (2^i)
The path is not the most efficient one, simplify as you wish.

sum+sum equation issue in GAMS

I defined the following equation to calculate the sum of total power consumed by the system:
TotalPower.. systemPower =e= sum(J,P(J)) + sum(I,CP(I));
However, the variable systemPower gets only the result of the second sum and not both!. The declaration of P(J) is as following:
P.LO(I)=0;
P.up(I)=100;
P.l('i1')=2;
P.l('i2')=3;
Please, Can any one explain why I get the result of a single sum? How I can do to get both?. I tried also to separate them in different values but yet I get the same result.
Thank you in advance.
I though it is a good idea to share this it might help someone else. I used a variable directly instead of an equation and I put it in the following form and it worked.
systemPower.l = sum(I,P.l(I))+sum(I,CP(I));

(VB.NET) Round to 2 decimals globally?

How can I make all the numbers that come up be rounded to 2 decimal places? What should I write in class level so that I don't have to write Math.Round(var, 2) a hundred times?
You can’t control this on the class level, nor should you.
You should control it where ever you output the numbers. But of course you don’t need to (and shouldn’t) repeat code over and over again: you can just make all output code call the same function.
Furthermore, you should not use Math.Round, and especially not in every computation (that will yield wrong results!). Instead, use String.Format to get the correct textual representation of your numbers, where you output them:
Shared Function Representation(number As Double) As String
Return number.ToString("#.##")
End Function

Multiple equations in one boolean statement

I think this is a really general programming question, since boolean syntax is more or less the same in a lot of common languages.
But still my question is for php and javascript mainly.
Suppose I want to write an if statement which returns true if a variable is equal to 2,3, or 5.
And this variable has a very long name, so like this:
if((An_Object_With_A_Long_Name.Has_Also_An_Array[With_An_Index_Too]==2)
|| (An_Object_With_A_Long_Name.Has_Also_An_Array[With_An_Index_Too]==3)
||(An_Object_With_A_Long_Name.Has_Also_An_Array[With_An_Index_Too]==5))
{
return true;
}
and I really want my code look shorter, it is less depressing to read it months after :)
so can I simplify this into something like
if(An_Object_With_A_Long_Name.Has_Also_An_Array[With_An_Index_Too]==2||3||5)
Thanks for help !
Cheater way out: For that if statement, assign An_Object_With_A_Long_Name to Object i. (If you plan to have to compare this variable several times, assign Object i the pointer of An_Object_With_A_Long_Name.