8 Replies - 5689 Views - Last Post: 12 October 2010 - 10:45 PM Rate Topic: -----

#1 brucezepplin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 11-November 09

The operator * is undefined for the argument type(s) float[], float[]

Posted 12 October 2010 - 06:34 AM

Hi guys, can any of you tell me how to fix this bug? I'm trying my hand at vector mulitplication with floats.

public float[] get_x() {
		return p[0];
	}

	public float[] get_y() {
		return p[1];
	}
	
	public float[] get_z() {
		return p[2];
	}
public void vectorMultiply(Point point) {
		p[0] = p[0] * point.get_x();
		p[1] = p[1] * point.get_y();
		p[2] = p[2] * point.get_z();
	}
	
	public float[][] p;


The error message I am getting is:

The operator * is undefined for the argument type(s) float[], float[]

Thanks in advance for any help!

what I am getting at is what can I replace the * operator with to make this work?

Is This A Good Question/Topic? 0
  • +

Replies To: The operator * is undefined for the argument type(s) float[], float[]

#2 masijade  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: The operator * is undefined for the argument type(s) float[], float[]

Posted 12 October 2010 - 06:35 AM

Edit: Nevermind. You need to define your own method for matrix/vector multiplication. (Or download libraries that already have the capability, and more, such as Colt from CERN.)

This post has been edited by masijade: 12 October 2010 - 06:36 AM

Was This Post Helpful? 0
  • +
  • -

#3 guido-granobles  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: The operator * is undefined for the argument type(s) float[], float[]

Posted 12 October 2010 - 07:03 AM

Unlike C++, Java does not allow operator overloading in order to do such thing like multiply two vectors. You will have to create a method which accept two vectors as parameters and returns either a Vector or a float as result of the operation.
Was This Post Helpful? 0
  • +
  • -

#4 brucezepplin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 11-November 09

Re: The operator * is undefined for the argument type(s) float[], float[]

Posted 12 October 2010 - 07:28 AM

Ok, perhaps then would it would beset to convert the floats to doubles. any idea how to do this?

I could avoid the problem above if i could convert the below float to a double. but can;t seem to get it to work

float[][] magneticVectorDiff = mvec.getMagneticVector();
			a = magneticVectorDiff.doubleValue();


I've defined a as

double[][] a;

Was This Post Helpful? 0
  • +
  • -

#5 guido-granobles  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: The operator * is undefined for the argument type(s) float[], float[]

Posted 12 October 2010 - 07:33 AM

You cannot asing a double value to a matrix of doubles. You can do this:
a[0][0]=magneticVectorDiff.doubleValue();


That is fine. But 'a' is a matrix and it is not a double value so you cannot to do this:
double[][]  a = magneticVectorDiff.doubleValue();


Was This Post Helpful? 0
  • +
  • -

#6 brucezepplin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 11-November 09

Re: The operator * is undefined for the argument type(s) float[], float[]

Posted 12 October 2010 - 07:51 AM

Are sure a should not at least be defined as at at least

Object[][] a


with this code:

a[magneticVectorDiff.length][magneticVectorDiff.length] = magneticVectorDiff.doubleValue();


a cannot be resolved and I'm still getting

Cannot invoke doubleValue() on the array type float[][].

bloody annoying! but you have helped me focus on the problem a lot better.

copy and paste went a bit haywire on the first line of that post
Was This Post Helpful? 0
  • +
  • -

#7 brucezepplin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 11-November 09

Re: The operator * is undefined for the argument type(s) float[], float[]

Posted 12 October 2010 - 08:02 AM

Im thinking I should be converting the float[][] to String and then to double[][]
Was This Post Helpful? 0
  • +
  • -

#8 guido-granobles  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: The operator * is undefined for the argument type(s) float[], float[]

Posted 12 October 2010 - 08:06 AM

You can cast the values:
float a = (float)5.6;
double b = (double)a;


Was This Post Helpful? 0
  • +
  • -

#9 masijade  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: The operator * is undefined for the argument type(s) float[], float[]

Posted 12 October 2010 - 10:45 PM

View Postbrucezepplin, on 12 October 2010 - 02:28 PM, said:

Ok, perhaps then would it would beset to convert the floats to doubles. any idea how to do this?

I could avoid the problem above if i could convert the below float to a double. but can;t seem to get it to work

float[][] magneticVectorDiff = mvec.getMagneticVector();
			a = magneticVectorDiff.doubleValue();


I've defined a as

double[][] a;


float or double same difference. You would still need to write a method, or use a library, to handle the matrix/vector operations.

View Postbrucezepplin, on 12 October 2010 - 02:51 PM, said:

Are sure a should not at least be defined as at at least

Object[][] a

Quote

If you want to use Float or Double instead of float or double, sure, but you don't need to, and would probably make the code much less effecient when it comes to the math operations.


with this code:

a[magneticVectorDiff.length][magneticVectorDiff.length] = magneticVectorDiff.doubleValue();


a cannot be resolved and I'm still getting

Cannot invoke doubleValue() on the array type float[][].

bloody annoying! but you have helped me focus on the problem a lot better.

copy and paste went a bit haywire on the first line of that post


Because you are trying to call methods on arrays. The Array type does not define very many methods (if any, non-private, really) and that is not going to work. Of course. You are going to need to loop through the arrays and perform the actual math on the elements as if you were actually doing this math with pen and paper. Or, as already said, a few times, get a library API that already has defined all this stuff, such as, as already said, again, the Colt library from CERN (CERN, you know, the science group that just built the largest particle accelerator on earth).

View Postguidojavier, on 12 October 2010 - 03:06 PM, said:

You can cast the values:
float a = (float)5.6;
double b = (double)a;



No need to cast a float to a double as the "widening" principle allows that assignment. You do, of course, need to cast from double to float, though.

View Postbrucezepplin, on 12 October 2010 - 03:02 PM, said:

Im thinking I should be converting the float[][] to String and then to double[][]


I'm sorry, but more idiocy here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1