473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

maths

i'm looking to do some maths, such as parsing equations into polymorphic
trees, matrices, etc. I've done it in C, a mess, but now i want to port it
to something less low level (read: less messy). C++ is good, but will i get
much improvement, ie regarding the polymorphic trees (trees whoses node can
be
either a multiplication, subtraction, matrix etc)? Anyone have any
suggestions, or some unbiased ideas regarding a good, modern, well supported
language to try. C# seems to have awful support in this area, no TYPEDEF
AGHHHH! lol. Haskell is good, no newsgroup support though. Maybe Java?

Cheers
dave

--
"Aristotle said that some people were
only fit to be slaves. I do not
contradict him. But I reject slavery
becase I see no people fit to be masters"
C.S Lewis
Jul 21 '05 #1
12 1481
David Sobey <ma**********@hotmail.com> wrote:
i'm looking to do some maths, such as parsing equations into polymorphic
trees, matrices, etc. I've done it in C, a mess, but now i want to port it
to something less low level (read: less messy). C++ is good, but will i get
much improvement, ie regarding the polymorphic trees (trees whoses node can
be
either a multiplication, subtraction, matrix etc)? Anyone have any
suggestions, or some unbiased ideas regarding a good, modern, well supported
language to try. C# seems to have awful support in this area, no TYPEDEF
AGHHHH! lol. Haskell is good, no newsgroup support though. Maybe Java?


Well, Java doesn't have typedef either. Do you really *need* typedef?
If that's one of your non-obvious requirements, perhaps you could list
your others?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
well, i used typedefs to make my basic data structures, ie matrices. i don't
want to be writing int[][] over and over again. and i don't really want to
have every node (ie a multiplication or addition node) as a class, i'd think
it's best to just have them as a compound data type. so i don't think this
can be done in c#. do you see where i'm heading with this?

cheers
dave
Jul 21 '05 #3
Hi David,

Maybe defining your own structures (value types with value semantics) could
be an option...

Hope this helps,
Regards,
Leon

"David Sobey" wrote:
well, i used typedefs to make my basic data structures, ie matrices. i don't
want to be writing int[][] over and over again. and i don't really want to
have every node (ie a multiplication or addition node) as a class, i'd think
it's best to just have them as a compound data type. so i don't think this
can be done in c#. do you see where i'm heading with this?

cheers
dave

Jul 21 '05 #4
sorry to have to play dumb but what does "defining your own structures
(value types with value semantics)" mean? an example, ie for a tree node or
a simple matrix array def would be nice.

thanks
dave
Jul 21 '05 #5
Take a look here

http://www.codeproject.com/csharp/structs_in_csharp.asp
Hope this helps,
Regards
Leon

"David Sobey" wrote:
sorry to have to play dumb but what does "defining your own structures
(value types with value semantics)" mean? an example, ie for a tree node or
a simple matrix array def would be nice.

thanks
dave

Jul 21 '05 #6
You can find more info here

Memory in .NET - what goes where
http://www.yoda.arachsys.com/csharp/memory.html

Delving into C# Structures
http://www.csharpfriends.com/Article...?articleID=120

Structs in C#
http://www.codeproject.com/csharp/structs_in_csharp.asp

Hope this helps,
Regards,
Leon
"David Sobey" wrote:
sorry to have to play dumb but what does "defining your own structures
(value types with value semantics)" mean? an example, ie for a tree node or
a simple matrix array def would be nice.

thanks
dave

Jul 21 '05 #7
ahh ok you mean use structs. fair enough, but how would i get around things
like defining matrix arrays, i can't keep on going int[][], and i can't put
it in a struct, because then i would end up passing single member structs
everywhere, which is stupid.

"Leon Welicki" <Le*********@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
Take a look here

http://www.codeproject.com/csharp/structs_in_csharp.asp
Hope this helps,
Regards
Leon

"David Sobey" wrote:
sorry to have to play dumb but what does "defining your own structures
(value types with value semantics)" mean? an example, ie for a tree node
or
a simple matrix array def would be nice.

thanks
dave

Jul 21 '05 #8
David Sobey <ma**********@hotmail.com> wrote:
ahh ok you mean use structs. fair enough, but how would i get around things
like defining matrix arrays, i can't keep on going int[][], and i can't put
it in a struct, because then i would end up passing single member structs
everywhere, which is stupid.


No it's not. It's encapsulation. Where would you put the methods to act
on those matrices? It makes perfect sense to put them in the
class/struct which encapsulates the matrix.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #9
hmmm you could be right! *brain starts ticking....*

thanks for your help!
cheers
dave
Jul 21 '05 #10
So, what was wrong with using this?

<code>
/// <summary>
/// Stores a 3 row by 3 column matrix representing a geometric transform.
/// Not inheritable.
/// </summary>
public sealed
class AffineMatrix
{

/// <summary>
/// Creates an <code>AffineMatrix</code> with the elements of the identity
matrix.
/// </summary>
public AffineMatrix ( )
: this ( new float [0x6] { 1F, 0F, 0F, 1F, 0F, 0F } )
{
}

/// <summary>
/// Creates an <code>AffineMatrix</code> with the specified elements.
/// </summary>
/// <param name="m11">The value in the first row and first column.</param>
/// <param name="m12">The value in the first row and second
column.</param>
/// <param name="m21">The value in the second row and first
column.</param>
/// <param name="m22">The value in the second row and second
column.</param>
/// <param name="m31">The value in the third row and first column.</param>
/// <param name="m32">The value in the third row and second
column.</param>
public AffineMatrix
( float m11, float m12, float m21, float m22, float m31, float m32 )
: this ( new float [0x6] { m11, m12, m21, m22, m31, m32 } )
{
}

private AffineMatrix ( float [] matrix )
{
this.matrix = matrix;
}

~AffineMatrix ( )
{
matrix = null;
}
#region Internal Members

/// <summary>
/// The six-element array that represent this <code>AffineMatrix</code>.
/// </summary>
internal float [] matrix = null;

#endregion
/// <summary>
/// Gets a six-element array that represent this
<code>AffineMatrix</code>.
/// </summary>
public float [] Elements
{
get
{
return matrix;
}
}

/// <summary>
/// Gets the current translation on the horizontal axis.
/// </summary>
public float OffsetX
{
get
{
return matrix [0x4];
}
}

/// <summary>
/// Gets the current translation on the vertical axis.
/// </summary>
public float OffsetY
{
get
{
return matrix [0x5];
}
}

/// <summary>
/// Gets a value indicating whether this <code>AffineMatrix</code>
/// equals the identity matrix.
/// </summary>
public bool IsIdentity
{
get
{
return 1F == matrix [0x0] && 0F == matrix [0x1]
&& 0F == matrix [0x2] && 1F == matrix [0x3]
&& 0F == matrix [0x4] && 0F == matrix [0x5];
}
}
/// <summary>
/// Resets this <code>AffineMatrix</code> to have the elements of the
identity matrix.
/// </summary>
public void Reset ( )
{
matrix [0x5]
= matrix [0x4]
= matrix [0x2]
= matrix [0x1]
= 0F;
matrix [0x3]
= matrix [0x0]
= 1F;
}

/// <summary>
/// Offsets the coordinates of this <code>AffineMatrix</code>.
/// </summary>
/// <param name="dx">Specifies the horizontal translation.</param>
/// <param name="dy">Specifies the vertical translation.</param>
public void Translate ( float dx, float dy )
{
matrix [0x4] = dx;
matrix [0x5] = dy;
}

/// <summary>
/// Applies a scale vector to this <code>AffineMatrix</code>.
/// </summary>
/// <param name="sx">Specifies the horizontal scale factor.</param>
/// <param name="sy">Specifies the vertical scale factor.</param>
public void Scale ( float sx, float sy )
{
matrix [0x0] = sx;
matrix [0x3] = sy;
}

/// <summary>
/// Applies a rotation to this <code>AffineMatrix</code>.
/// </summary>
/// <param name="sx">Specifies the horizontal scale factor.</param>
/// <param name="sy">Specifies the vertical scale factor.</param>
public void Rotate ( float sx, float sy )
{
/*
Rotations are produced by [cos 0 sin 0 -sin 0 cos 0 0 0], which has the
effect
of rotating the coordinate system axes by an angle 0 counterclockwise.
*/
// matrix [0x0] = sx;
// matrix [0x3] = sy;
throw new System.NotImplementedException();
}

/// <summary>
/// Creates an exact copy of this <code>AffineMatrix</code>.
/// </summary>
/// <returns>An instance copy.</returns>
public AffineMatrix Clone ( )
{
return new AffineMatrix( new float [0x6]
{ matrix [0x0], matrix [0x1]
, matrix [0x2], matrix [0x3]
, matrix [0x4], matrix [0x5] } );
}
}

</code>
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"David Sobey" <ma**********@hotmail.com> wrote in message
news:41***********************@news.optusnet.com.a u...
hmmm you could be right! *brain starts ticking....*

thanks for your help!
cheers
dave

Jul 21 '05 #11
that matrix handling seems orientated towards graphics. I'm referring to
lower level matrix ops, such as determinants and row-reduction.

cheers
dave
Jul 21 '05 #12
Well, then yes it is too simple.
I am also interested in a such utility.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"David Sobey" <ma**********@hotmail.com> wrote in message
news:41***********************@news.optusnet.com.a u...
that matrix handling seems orientated towards graphics. I'm referring to
lower level matrix ops, such as determinants and row-reduction.

cheers
dave

Jul 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jack Higgs | last post by:
Has anyone got any ideas how I could go about producing a maths program for Primary School pupils? The coding isn't such a problem (ie random numbers etc), it's acctually figuring out how to...
5
by: Scott Gunn | last post by:
Hello All, In VB.Net 2003 why is this the result to a simple maths calculation? 3.53 - 3.52 = 0.00999999046325684 Its not just this one either try this: 1.001 - 0.001 = 0.999999999999989
20
by: Daisy | last post by:
Something simple, I'm sure. My code: System.Windows.Forms.MessageBox.Show(((Int32)Math.Ceiling(1966 / 100)).ToString()); I'm expecting 20, but getting 19. What am I doing wrong? Thanks --
6
by: David Sobey | last post by:
hi everyone i'm looking to make a program that not only implements some fancy control stuff with GDI+, but does some tricky maths using polymorphic binary data trees, matrices, etc. Now I've...
9
by: uttre | last post by:
hai to all, i did some programming in Lisp (6 months) & next i want to learn C++. i searched all the archives of "comp.lang.c++" & ACCU too & decided "C++ Primer" 3/e as my text book....
3
by: hars2010 | last post by:
hey i got this assignment in maths.i really need help guys.the question is below.The program should: It first clears the screen and then displays the next 3 lines. a1x + b1y + c1y =d1 a2x +...
1
by: jwatson | last post by:
Write a program to find the roots of quadratic equation. User will key the "a","b","c", for the equation ax*x+b*x+c = 0. formula given as x = (-b(+)(-) sqrt(b*b-4ac)/2a. Prog1: Only find the real...
5
by: Ibys | last post by:
Hi, i am just starting to learn javascript, so i am probably doing something very simple wrong. i have read a lot of articles on maths in java, but cant find anything simple enough for my problem. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.