Question

Matrix Programming

Asked by: currir55

I am looking into building a program which can perform varying matrix manipulations and calculations as well as function as a sort of matrix calculator, at this time I am looking into the best way to build a GUI for my interface (writtien idealy in C or C++ if not).
Also what is the best way to link a matrix input from the GUI interface into a Matrix in my program.
I cannot offer any source code to help you give me any advice on as I am still in the process of writing it but I am nearing completing my program and I am looking into the GUI and usability aspects oif its design, as of now I am still working in the Command prompt and so even a simple guide to GUI building is appreciated or even a link to a good tutorial.
This is my first major programming endevour so any help is greatly appreciated. I am only writing for myself but I hope to make a reasonable effort at it.
Also if someone can point me in the rought direction for writing code to plot a 3-D matrix this would be greatly appreciated. I have found information on 2-d plotting but I dont know where to start for plotting 3-D objects in C.
PS I prefer the Linux OS and/or OpenSource tools

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-06-08 at 05:36:10ID21017322
Tags

matrix

,

c

,

programming

Topic

C Programming Language

Participating Experts
3
Points
75
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Matrix
    Is Matrix class (for numeric computing) available?
  2. matrix operations
    is there is any source code for vb program that do matrix operation such as determinant,multiply,adjacent,reverse,...etc
  3. Matrix
    I have only been taught with the AP class files, (apmatrix,apstring,apvector,etc), but I would like to make a console program using the standard C++ matrix. How do I declare an empty and unsized matrix of type char? I know to declare a char of an undetermined length to do c...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Fippy_DarkpawPosted on 2004-06-08 at 13:12:48ID: 11263850

If you were on Windows I would suggest just using the DirectX math libraries. It has all vector and matrix operations built in.

Use OpenGL for the plotting, nice cross-platform solution. There are REALLY good openGL tutorials at nehe.gamedev.net

If you want to implement the matrices yourself they arent too hard. Just make a class Matrix that holds some 2D arrays. For example,

class Matrix
{
     float matrix[rows][columns];
     Matrix add();
     Matrix multiply();
     Matrix transpose(); etc....
}

Then build in addition, subtraction, multiplication, transpose etc....

Here's some algorithms:

Algorithm #1 – Matrix Addition
            for (i = 0; i < n; i++)
                  for (j = 0; j < n; j++)
                        A[i][j] = B[i][j] + C[i][j];

Algorithm #2 – Matrix Multiplication
            for (i = 0; i < n; i++)
                  for (j = 0; j < n; j++)
                        for (k = A[i][j] = 0; k < n; k++)
                              A[i][j] += B[i][k] * C[k][j];

Algorithm #3 – Matrix Transposition
            for (i = 0; i < n-1; i++)
                  for (j = i+1; j < n; j++){
                        temp = A[i][j];
                        A[i][j] = A[j][i];
                        A[j][i] = temp;
                  }


 

by: Fippy_DarkpawPosted on 2004-06-08 at 13:15:02ID: 11263873

Here's some vector math functions I used in an OpenGL program a while back. They are pretty self explanatory. I would start with vectors before you do matrices.

void vectorCopy(float dest[3], float src[3])       //  vector copy
{
      dest[0] = src[0];
      dest[1] = src[1];
      dest[2] = src[2];
}

void vectorScale(float dest[3], float v[3], float s)  // vector times scalar
{
      dest[0] = v[0]*s;
      dest[1] = v[1]*s;
      dest[2] = v[2]*s;
}

void vectorAdd(float dst[3], float srcA[3], float srcB[3])  //  vector add
{
    dst[0] = srcA[0] + srcB[0];
    dst[1] = srcA[1] + srcB[1];
    dst[2] = srcA[2] + srcB[2];
}

void vectorSubtract(float dst[3], float srcA[3], float srcB[3]) // vector subtract
{
    dst[0] = srcA[0] - srcB[0];
    dst[1] = srcA[1] - srcB[1];
    dst[2] = srcA[2] - srcB[2];
}

float getLength(float A[3])    // magnitude of vector
{
      return sqrt( (A[0]*A[0])+(A[1]*A[1])+(A[2]*A[2]));
}

void normalize (float vec[3])  // Normalize vector
{
    const float squaredLen = vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2];
    const float invLen = 1.f / (float) sqrt (squaredLen);
    vec[0] *= invLen; vec[1] *= invLen; vec[2] *= invLen;
}

float dot(float A[3], float B[3])      // dot product
{
      return      ( A[0]*B[0] + A[1]*B[1] + A[2]*B[2]);
}

 

by: Fippy_DarkpawPosted on 2004-06-08 at 13:21:17ID: 11263939

Here's a really nice link that explains matrix math theory and how it directly relates to coding. Provides examples as well:

http://www.morrowland.com/apron/article/technical/matrix/index.php

 

by: currir55Posted on 2004-06-08 at 13:48:37ID: 11264151

Just to try and make myself a bit clearer.

I am studying A levels in further maths and maths and so I am aware of matrix mathematics but thanx all the same.

As I said although this is my first major software project I have some experience in programming and have had varying success in altering other peoples source code to meet my needs, however this is my first piece of solo work.

Thanx anyway however as the algorithms above have saved me repeating code for varying matrix size, strange how it never occured to me to write an algorithm, I was just planning on writing repetitive code as it's easier to debg for now, but I'll give your code a try, thanx.

As well as this again thankyou for the help with the vectors, I havent been experiecing problems with the vectors in my code it has mainly been with the GUI and matrices.

I am mainly stuck now with writing code to allow me to solve the determinant of 3x3 and 4x4 matrices. I dont think I need help with it it jus seems to be long and complex.


Thanx a lot guys for the information so far, I dont know how seriously you take the points system on this site but I'll wait another 24 hours before I choose who to give them to, but all the replies so far have been exellent and exactly what I have been after.

 

by: Fippy_DarkpawPosted on 2004-06-08 at 15:25:41ID: 11264897

Link to java and c++ code for matrix determinant:

http://www.euclideanspace.com/maths/algebra/matrix/functions/determinant/

They used the brute force method which is probably fastest execution-wise, it sure is ugly though hehe:

public final double determinant() {
    double value;
    value =
      m03 * m12 * m21 * m30-m02 * m13 * m21 * m30-m03 * m11 * m22 * m30+m01 * m13 * m22 * m30+
      m02 * m11 * m23 * m30-m01 * m12 * m23 * m30-m03 * m12 * m20 * m31+m02 * m13 * m20 * m31+
      m03 * m10 * m22 * m31-m00 * m13 * m22 * m31-m02 * m10 * m23 * m31+m00 * m12 * m23 * m31+
      m03 * m11 * m20 * m32-m01 * m13 * m20 * m32-m03 * m10 * m21 * m32+m00 * m13 * m21 * m32+
      m01 * m10 * m23 * m32-m00 * m11 * m23 * m32-m02 * m11 * m20 * m33+m01 * m12 * m20 * m33+
      m02 * m10 * m21 * m33-m00 * m12 * m21 * m33-m01 * m10 * m22 * m33+m00 * m11 * m22 * m33;
    return value;
  }

 

by: Fippy_DarkpawPosted on 2004-06-08 at 15:27:10ID: 11264902

Oh there is C++ source on that page for determinant of any size matrix too...wish you could edit these comments heh =)

 

by: akshayxxPosted on 2004-06-08 at 19:51:09ID: 11266146

First you need to specify what platform are you looking for,  and any specific programming language..

since u have posted this in C section , i presume that u are most comfortable with C.
in that case i would suggest you to go for GTK2.x ,
it has UI widgets with which you can associate a data model, say a table( gui equivalent of maths' matrix).
advantage of it is that whatever changes you do in your back-end data model, it is automatically reflected in the associated UI widget. and its faster too. and many other advatages over the old methods of having separate UI and backend data structs.

In case you are familiar with java, then i would suggest that over C, because of its platform independency and ease of UI programming. and in that too go for jfc/swing stuff

For C++ QT is the best option i can think of, it might take some inertia to get started with qt, but for most of ur requirements u can find examples to start with...and its available on many platforms..

also if u want some maths library, which can provide all the matrix operations API, then i can suggest one. ( so that u dont waste time implementing matrix operations).
hope this helps
akshay


 

by: akshayxxPosted on 2004-06-08 at 19:52:58ID: 11266150

seems i didnt read ur requirements completely,
for ur 3-d plotting, i would suggest exploring appropriate part of source code of gnuplot.


 

by: fridomPosted on 2004-06-08 at 23:43:00ID: 11267010

How about http://www.linmpi.mpg.de/dislin/  ?

Regards
Friedrich

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...