How to implement Foulke's algorithm in C [closed] - c

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Foulke's algorithm is defined by
(In + U)2 = In+ U + U2
with:
In : the identity matrix
U : square adjacent matrix
I want to implement this algorithm in C by recurrence.
Any help is appreciated.

Your formula is wrong. Substitute U with identity matrix and you will see that the equality does not hold. You need to change it to (In + U)^2 = In+ 2*U + U^2. Just like numbers. Makes sense, huh?
Otherwise all you need to do is to implement a function that multiplies to two-dimensional matrices and returns the result in a two-dimensional array. I don't think using recursion for this problem is a good option.

I recommend you to use BLAS library. Or you want to make all yourself without any algebra-library?

Related

calling array in function [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am new to C , and i am working on a program in C to evaluate RHS of green's theorem
Those who don't know about green's theorem here is
LINK
from wikipedia.
Now concerning the Right hand side (RHS) of green's theorem , it requires partial differentiation and double integrtation .
I have coded a program in C to calculate partial differentiation of M and L wrt x and y respectively.
Here is the code for it .
Now here comes the problem as you can see that f() is a function which is to be integrated , and our case it is e[i]-d[j] from the first code . Now the problem is e[i]-d[j] is an array of points so when the function f(u,v) call its value it should return the corresponding values of function at that point. Thus say for example we get f(1,0.8) , then the function e[i]-d[j] should return the value at i=1 and j=0.8 which is not possible subscript of array can't be of float type. So here i am stuck how to call the values from function f.
Any help would be gratly appreciated .
Where do you get the values between 0 and 1? Do you just compute the value from i,j on the fly? On your first part of the program only value with int index is computed.
No way to store value using float i,j as array index. If you insist on using the float as index. May be c++ STL map can help you. You can just use i+j as the key to index the values.
Multiply the number of points you are playing with by a constant factor - say 10 for your example. Then you can multiply your array subscript by the same. In your example, 1, 0.8 becomes (10, 8) and works fine. This is a variation on fixed point math if you are interested.

Sorting with just one loop. Help me with its efficiency [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have came up with a new sorting algorithm with just one do while loop in it, but i don't
know how to calculate the efficiency of it in best,average and worst case so please help me in calculating it.
The loop starts with i=1 and the end condition for while loop is i<=n-2 and some times the value of i increases in the loop and some times i value will be decremented based on some condition.
I think i will better understand if u illustrate through simple examples.
please help me............
Thank you in advance for those who help me.....
some times i value will be decremented based on some condition
This vagueness makes it impossible to analyze. If the "condition" is always true and i is decremented to zero, then the loop runs forever. So based on what you say, the time complexity could be anything from Theta(n) to infinity.
The way to work out time complexity is to calculate (or put an upper bound on) the number of operations performed, as a function of n. "Operations" in the case of sorting usually means comparisons and copies/moves, but if your algorithm does anything unusual then of course that has to be included.

How to write a C program of two bodies exerting a gravitational force on each other? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I 've been set the following problem and don't have a clue how to start any help would be much appreciated.
In 2-D, read in the initial positions, velocities and masses of two bodies (suns, stars etc) . You will need to define suitable units for these. Then using the gravitational equation, calculate the force on each body from the other, and use Newton’s 3rd law to calculate the acceleration of that body. Generate a file with the positions of both bodies at each timestep for a long time period. Use this file to plot the paths of the two bodies.
Store the initial position, velocity and masses.
Calculate the magnitude and direction of the gravitational force.
Knowing the force, you can calculate the acceleration of each body.
Knowing the acceleration you can calculate the new velocity.
Knowing the velocity you can calculate the new position.
Using suitably small time steps you can get a reasonably good approximation to continuous motion.

database design and algorithm for Public Transport? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
We want to implement Public Transport Guide for Android.
Inputs will be beginning and destination point. Outputs will be the directives that
tell how can be gone to the destination with using buses, subways,... e.c
This is not easy for big cities and we must have a well-designed database for quick answer. Tranport algorithm must give optimum lines to the passanger.
I wanna see your precious ideas for database and algorithm design.
Thank you very much for answers.
Most likely you will need a graph there to calculate shortest path.
Your graph will be G=(V,E) such that V = {all possible stations} and E = {(u,v) | there is a transport connecting station u to station v}.
If your graph cannot fit into memory [which is probably the case for a big city], you might want to make a function successors(u) = { v | (u,v) in E } which will allow you to calculate the graph on the fly.
In this older question there is some discussion how to efficiently find a path between two vertices in a dynamic environment similar to the one you are describing.

How to Generate bit mask for a number from the number itself? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Is there any way with which I can generate bit mask of a number without changing the number itself?
I am new to programming and I have seen hard-coded bit-masks only.
Can we do any operations on the number to generate the bitmask, from the number itself (i.e.: a dynamically generated mask, depending the value of the number)
Thanks.
Why not? Use the number itself as a mask:
//returns true if bit n is 1 and false otherwise
bool get(int index, int mask)
{
return (mask >> index) & 1;
}

Resources