Click here to Skip to main content
15,926,062 members
Home / Discussions / C#
   

C#

 
GeneralRe: category for beginners? Pin
Ranger4931-Jan-07 9:31
Ranger4931-Jan-07 9:31 
GeneralRe: category for beginners? Pin
Pete O'Hanlon31-Jan-07 9:42
mvePete O'Hanlon31-Jan-07 9:42 
GeneralRe: category for beginners? Pin
Luc Pattyn31-Jan-07 11:35
sitebuilderLuc Pattyn31-Jan-07 11:35 
GeneralRe: category for beginners? Pin
Colin Angus Mackay31-Jan-07 11:31
Colin Angus Mackay31-Jan-07 11:31 
GeneralRe: category for beginners? Pin
Christian Graus31-Jan-07 14:53
protectorChristian Graus31-Jan-07 14:53 
GeneralRe: category for beginners? Pin
Ranger4931-Jan-07 16:37
Ranger4931-Jan-07 16:37 
AnswerRe: category for beginners? Pin
ednrgc1-Feb-07 3:45
ednrgc1-Feb-07 3:45 
QuestionWhy doesn't this work? Pin
Ranger4931-Jan-07 7:36
Ranger4931-Jan-07 7:36 
using System;
using System.Collections.Generic;
using System.Text;

namespace Operator3
{
class Matrix
{
double a11;
double a12;
double a13;
double a14;
double a21;
double a22;
double a23;
double a24;
double a31;
double a32;
double a33;
double a34;
double a41;
double a42;
double a43;
double a44;

public Matrix(double Ina11, double Ina12, double Ina13, double Ina14, double Ina21, double Ina22, double Ina23, double Ina24, double Ina31, double Ina32, double Ina33, double Ina34, double Ina41, double Ina42, double Ina43, double Ina44)
//this method should make an instance of the class Matrix, instead I get the error message that the name Matrix is the same as the name of the class so that it isn't allowed. I haven't got a clue why this doesn't compile!
{
this.a11 = Ina11;
this.a12 = Ina12;
this.a13 = Ina13;
this.a14 = Ina14;

this.a21 = Ina21;
this.a22 = Ina22;
this.a23 = Ina23;
this.a24 = Ina24;

this.a31 = Ina31;
this.a32 = Ina32;
this.a33 = Ina33;
this.a34 = Ina34;

this.a41 = Ina41;
this.a42 = Ina42;
this.a43 = Ina43;
this.a44 = Ina44;
}

public static Matrix operator *(Matrix M1, Matrix M2)
{
// the compiler doesn't seem to have a problem here
return new Matrix(
//kolom 1
M1.a11 * M2.a11 + M1.a21 * M2.a12 + M1.a31 * M2.a13 + M1.a14 * M2.a14,
M1.a12 * M2.a11 + M1.a22 * M2.a12 + M1.a32 * M2.a13 + M1.a24 * M2.a14,
M1.a13 * M2.a11 + M1.a23 * M2.a12 + M1.a33 * M2.a13 + M1.a34 * M2.a14,
M1.a14 * M2.a11 + M1.a24 * M2.a12 + M1.a34 * M2.a13 + M1.a44 * M2.a14,
//kolom 2
M1.a11 * M2.a21 + M1.a21 * M2.a22 + M1.a31 * M2.a23 + M1.a14 * M2.a24,
M1.a12 * M2.a21 + M1.a22 * M2.a22 + M1.a32 * M2.a23 + M1.a24 * M2.a24,
M1.a13 * M2.a21 + M1.a23 * M2.a22 + M1.a33 * M2.a23 + M1.a34 * M2.a24,
M1.a14 * M2.a21 + M1.a24 * M2.a22 + M1.a34 * M2.a23 + M1.a44 * M2.a24,
//kolom 3
M1.a11 * M2.a31 + M1.a21 * M2.a32 + M1.a31 * M2.a33 + M1.a14 * M2.a34,
M1.a12 * M2.a31 + M1.a22 * M2.a32 + M1.a32 * M2.a33 + M1.a24 * M2.a34,
M1.a13 * M2.a31 + M1.a23 * M2.a32 + M1.a33 * M2.a33 + M1.a34 * M2.a34,
M1.a14 * M2.a31 + M1.a24 * M2.a32 + M1.a34 * M2.a33 + M1.a44 * M2.a34,
//kolom 4
M1.a11 * M2.a41 + M1.a21 * M2.a42 + M1.a31 * M2.a43 + M1.a14 * M2.a44,
M1.a12 * M2.a41 + M1.a22 * M2.a42 + M1.a32 * M2.a43 + M1.a24 * M2.a44,
M1.a13 * M2.a41 + M1.a23 * M2.a42 + M1.a33 * M2.a43 + M1.a34 * M2.a44,
M1.a14 * M2.a41 + M1.a24 * M2.a42 + M1.a34 * M2.a43 + M1.a44 * M2.a44);
}
}



public class Vector
{
double v1, v2, v3, v4;

public Vector(double v1, double v2, double v3, double v4)
//This won't compile, why won't this method just create an instance of the class Vector?
{
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.v4 = v4;
}

public static Vector operator *(Matrix M, Vector V)
{
return new Vector(
M.a11 * V.v1 + M.a12 * V.v2 + M.a13 * V.v3 + M.a14 * V.v4,
M.a21 * V.v1 + M.a22 * V.v2 + M.a23 * V.v3 + M.a24 * V.v4,
M.a31 * V.v1 + M.a23 * V.v2 + M.a33 * V.v3 + M.a34 * V.v4,
M.a41 * V.v1 + M.a24 * V.v3 + M.a43 * V.v3 + M.a44 * V.v4);

}
}

class Program
{
static void Main(string[] args)
{
Matrix M = new Matrix(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
Vector V = new Vector(1.0, 0.0, 0.0, 0.0);
}
}
}

//This version is really my 2nd attempt of making a class that defines and multiplies matrices and vectors. So I am a newbe. Please give me some advice.

Beginner.
AnswerRe: Why doesn't this work? Pin
Luc Pattyn31-Jan-07 7:58
sitebuilderLuc Pattyn31-Jan-07 7:58 
AnswerRe: Why doesn't this work? Pin
Patrick Etc.31-Jan-07 8:59
Patrick Etc.31-Jan-07 8:59 
GeneralRe: Why doesn't this work? Pin
Ranger4931-Jan-07 9:14
Ranger4931-Jan-07 9:14 
QuestionA generic error occurred in GDI+. Pin
ThetaClear31-Jan-07 6:09
ThetaClear31-Jan-07 6:09 
AnswerRe: A generic error occurred in GDI+. Pin
ednrgc31-Jan-07 6:46
ednrgc31-Jan-07 6:46 
AnswerRe: A generic error occurred in GDI+. Pin
Luc Pattyn31-Jan-07 8:16
sitebuilderLuc Pattyn31-Jan-07 8:16 
AnswerLuc is right on Pin
Ennis Ray Lynch, Jr.31-Jan-07 9:57
Ennis Ray Lynch, Jr.31-Jan-07 9:57 
Questionconstructor fires when?? Pin
Brendan Vogt31-Jan-07 6:03
Brendan Vogt31-Jan-07 6:03 
AnswerRe: constructor fires when?? Pin
Wizard_0131-Jan-07 6:08
Wizard_0131-Jan-07 6:08 
AnswerRe: constructor fires when?? Pin
Colin Angus Mackay31-Jan-07 6:41
Colin Angus Mackay31-Jan-07 6:41 
QuestionDateTimeMonthPicker Pin
Pratik Vasant Shah31-Jan-07 5:44
Pratik Vasant Shah31-Jan-07 5:44 
AnswerRe: DateTimeMonthPicker Pin
Luc Pattyn31-Jan-07 8:11
sitebuilderLuc Pattyn31-Jan-07 8:11 
QuestionRe: DateTimeMonthPicker Pin
Pratik Vasant Shah31-Jan-07 19:27
Pratik Vasant Shah31-Jan-07 19:27 
AnswerRe: DateTimeMonthPicker Pin
Luc Pattyn1-Feb-07 1:12
sitebuilderLuc Pattyn1-Feb-07 1:12 
QuestionRe: DateTimeMonthPicker Pin
Pratik Vasant Shah1-Feb-07 2:03
Pratik Vasant Shah1-Feb-07 2:03 
AnswerRe: DateTimeMonthPicker Pin
Luc Pattyn1-Feb-07 2:16
sitebuilderLuc Pattyn1-Feb-07 2:16 
AnswerRe: DateTimeMonthPicker Pin
Luc Pattyn1-Feb-07 5:13
sitebuilderLuc Pattyn1-Feb-07 5:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.