|
Ok, let's take O2 + H2 = H2O then.
First I'll assign variables to the molecules:
O2 = x0
H2 = x1
H2O = x2
Then I build the equations, one for each element, the coefficients are how much of the current element is in the corresponding molecule:
H: 0 x0 + 2 x1 - 2 x2 = 0 // there is zero H in O2, 2 H in H2, 2 H in H2O
O: 2 x0 + 0 x1 - 1 x2 = 0 // there is 2 O in O2, zero O in H2, 1 O in H2O
The smallest solution where all variables are integers is x0 = 1, x1 = 2, x2 = 2, which corresponds to O2 + 2 H2 = 2 H2O
|
|
|
|
|
Hi,
OK that helps a little better, but I would have no idea how to implement this into code. It has gave me something to think about though.
Thank you again,
Stephen
|
|
|
|
|
As others have noted, the problem can be re-stated in terms of a system of linear equations. A particularly easy method to solve such systems (in relative terms, of course - it's a decent homework assignment for a second-year CS student) is the method of Gaussian Elimination[^].
Here is a Java implementation of what you are trying to build[^], conveniently packaged with a source code. The implementation is very easy to follow, even if you do not know Java (but do know some C#).
Good luck!
|
|
|
|
|
Thank you everyone for your help.
However, I think as a complete beginner, I may have bitten off more than I can chew, as I dont have a clue where to start based on the information provided.
Thank you again,
Stephen
|
|
|
|
|
If college chemistry can offer me anything it was that no equation balancer should be based on text input. The one I had to use was so bad I dared the prof. to fail me because I wasn't going to waste my time discovering how it wanted me to type.
Graphics and numeric up downs in a visually appealing manner are the way to go.
|
|
|
|
|
Lets start with a piece from the book:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TernaryOperator
{
class Time
{
int Year;
int Month;
int Date;
int Hour;
int Minute;
int Second;
public void DisplayCurrentTime()
{
Console.WriteLine("{0}/{1}/{2} {3}:{4}:{5}",
Month, Date, Year, Hour,Minute,Second);
Console.ReadKey();
}
public Time(System.DateTime dt)
{
Year = dt.Year;
Month = dt.Month;
Date = dt.Day;
Hour = dt.Hour;
Minute = dt.Minute;
Second = dt.Second;
}
}
class Program
{
static void Main(string[] args)
{
System.DateTime currentTime = System.DateTime.Now;
Time t = new Time(currentTime);
t.DisplayCurrentTime();
}
}
}
For the constructor portion, where I declared or created the reference in the constructor, the values aren't actively stored in my variables yet, am I right?
Year = dt.Year;
Month = dt.Month;
Date = dt.Day;
Hour = dt.Hour;
Minute = dt.Minute;
Second = dt.Second;
So that means my 'Time t = new Time(currentTime)' is storing the active vars into my constructor using the 'dt' reference?. Correct? I feel like I am almost lost.
|
|
|
|
|
Herboren wrote: the values aren't actively stored in my variables yet
Yes, they are, why do you think otherwise?
int s are value types.
|
|
|
|
|
Time t = new Time(currentTime);
The above code calls the constructor that takes a System.DateTime as input, and copies the values from the DateTime into the new object's variables. So you now have a Time object containing values that correspond to the currentTime object. The next line calls the DisplayCurrentTime() method on the Time object t , which displays the values previously stored.
Does that make sense?
The best things in life are not things.
|
|
|
|
|
Actually that made perfect sense and your put me back on track thank you. And these are all initialized explicitly, correct? And I can implicitly initialize it but changing 'int Second = 30;' as an initializer, not that I would want to but just to get the understanding of implicit and explicit.
|
|
|
|
|
Herboren wrote: And these are all initialized explicitly, correct?
Yes, statements of the form:
Year = dt.Year;
are taking a value from the input parameter (dt ) and allocating them to a variable within the current instance of the Time class; i.e. the object currently being constructed by the constructor.
Herboren wrote: And I can implicitly initialize it but changing 'int Second = 30;' as an initializer, not that I would want to but just to get the understanding of implicit and explicit.
I'm not sure I understand what you mean here: any statement of the form, variable = expression , is an explicit assignment, and can be placed anywhere, either within one of the class methods, or external to it when the access level of a variable allows. For a further discussion of explicit/implicit take a look here[^].
The best things in life are not things.
|
|
|
|
|
Hi,
Don't know whether it is right place to post this. If not, please suggest me the right forum.
I indexed the document using Lucene Indexer.
Each document contains the values for the Level, Parent, Description.
I would like to search the documents based on below conditions,
where Description contains "Ana", Level=0 and Parent not equal to "Move". I wrote the below code to satisfy those conditions
TermQuery qry = new TermQuery(new Term("Level", "0"));
WildcardQuery wQry = new WildcardQuery(new Term("Description", "*Ana*"));
QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Entity",
new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
Query qry1 = parser.Parse("Parent:NOT Move");
BooleanQuery boolQuery = (BooleanQuery)boolQuery.Combine(new Query[] { qry, wQry, qry1 });
boolQuery.Add(query, BooleanClause.Occur.MUST);
boolQuery.Add(wQry, BooleanClause.Occur.MUST);
boolQuery.Add(query3, BooleanClause.Occur.MUST);
hits = searcher.Search(boolQuery, 100);
qry and wQry are working but qry1 is not working. How to query Parent not equal to "Move".
Thanks in advance.
|
|
|
|
|
Ask the people you got the library from. It's is extremely unlikely that anyone that has any experience with your exact library is ever going to see your post.
|
|
|
|
|
I beleive you just need to use
BooleanClause.Occur.MUSTNOT
instead of
BooleanClause.Occur.MUST
Also don't use the NOT in the qry1.
|
|
|
|
|
Thank you, dmoses48. its working
|
|
|
|
|
Hi, suppose I have
var A = new[]
{
new {Name ="Car", N = 2},
new {Name ="Bike", N = 100}
};
var B = new[]
{
new {Name ="Car", N = 10},
new {Name ="Plane", N = 1}
};
I would like to to the following using LINQ syntax: Join A nd B getting a total collection summing also N where same objects are the same... to be clear the final output should be:
{Name ="Car", N = 12},
{Name ="Bike", N = 100},
{Name ="Plane", N = 1}
Thanks for your time
|
|
|
|
|
Here you go:
var query = from item in A.Union(B)
group item by item.Name into grp
select new { Name = grp.Key, N = grp.Sum(t => t.N) };
modified on Wednesday, July 20, 2011 10:46 AM
|
|
|
|
|
Suppose now I have many var. So not only two (A and B) but many, let's say A,B,C....
Is it still managable? (I mean a union between many and not anly two)
|
|
|
|
|
Why not try it out and see what effect it has?
|
|
|
|
|
I'm only able to do union between two at time. My question is if I can do between many at the same time.
|
|
|
|
|
And still I ask, why not try it out for yourself? You have the basic knowledge now, so it cannot be that hard for you to formulate your own opinion. Still, you can one vote this answer as well because I haven't spoonfed you the answer, rather I've suggested that you should now be able to think for yourself.
|
|
|
|
|
Hello Everybody,
I have a polygon like :
A.......B...................C
. . .
. . .
D.......E ..................F
and My Starting Point is
A and I want to visit all the Points of Polygon.
And The Incoming of A is From B and D and Both.
So Solution For A is :
A <B
A < D
A < B,D
So pls how can i Generate All the Combinations of this polygon.
Thanks
If you can think then I Can.
|
|
|
|
|
what have you tried yourself?
V.
|
|
|
|
|
DateTime Data Problems in Silverlight and C#
Hello Forum.
I am using VISI Fire in Silverlight and C# to produce some data charts. One style of chart allows stacked data to be displayed in colums the xaml code I am using looks like this
[IMG]http://i67.photobucket.com/albums/h292/Athono/xaml.png[/IMG]
The chart i am trying to build is based on a visi fire chart example. if you go to http://www.visifire.com/silverlight_wpf_charts_gauges_gallery.php and look at their stacked examples here http://www.visifire.com/silverlight_stacked_charts_gallery.php you can see the xaml example I am trying to emulate.
http://i67.photobucket.com/albums/h292/Athono/post_this.png
But my chart comes out differently. mine has this odd overlaping date feature
[IMG]http://i67.photobucket.com/albums/h292/Athono/badrepresentation.png[/IMG]
Now, I have carefully stepped through the code and as far as I can tell, I have the same date for each data set pair.
[IMG]http://i67.photobucket.com/albums/h292/Athono/code-1.png[/IMG]
I have stepped through this code and I have made sure that with each value for i, the years and the months for each data pair are exactly the same. So why is my graph so messed up?
|
|
|
|
|
Hi,
Maybe I'm not in the right forum. If so, accept my apologies and please re-direct me.
I am trying to install 'MS Visual Web Developer 2010 Expres' Actually I first installed Web Matrix, found it crap, and decided on the Next. First un-installed Web Matrix. Tried to install Visual Web Developer 2010 Express, it started with wanting to install SQL Express. Failed First, (After 2 hours) ostensibly because my disk was compressed.(Could that not have been detected early during setup, if that's a problem) Cloned the disk to a Larger One,usinf EaseUS, Undid the compression( as far as I could, went throuhg All Directories)(Some Files could not be Decompressed because they where in Use).
Tried Again. Got a message box: 'Installation Failed\nThe Version of SQL Express you are installing is Older than the version you have.'
Tried to use Windows Installer to uninstall. Started First to Last for SQL Server products,as listed. -:Fails on 'Cannot Uninstall this Component because other components are depending on it.'
Cloned the disk again to another disk, and started manually uninstalling components from the bottom to the Top, using Windows Uninstaller in other following orders, got messages:- To Uninstall This Component, you need XXXAXP DLL.
Rethorical Question, Why does a Microsoft Product not meet the Ms Uninstal/Failure to install specification written by microsoft themselves.
Question2, the Real question,
Where do I go from Here!
any help appreciated
Regards,
Bram van Kampen
|
|
|
|
|
Well we are stabbing in the dark now so try installing Web Express on one of the uncomrpessed disks. Sounds like you now have SQL Express installed.
"You get that on the big jobs."
|
|
|
|
|