Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
??? Error using ==> mpower

Subject: ??? Error using ==> mpower

From: Sid Hayes

Date: 2 Jan, 2009 15:10:04

Message: 1 of 5

Hi

I am trying to implement a formula for total force. Its seems to give me a run-time error during execution.

the error is:
??? Error using ==> mpower
Matrix must be square.

Error in ==> TFalgorithm at 26
        En = sum((q(i)*(R-R(i)))/(constant*(abs(R-R(i))^3)));

my algorithm is:
clear all;
% User to enter number of charges (N) to be placed on rod.
    N=input('Enter number of charges: ');

% Position N charges on the rod randomly.
    intN=int32(N);
    % Get the random numbers, and sort them.
    R = sort(2 * rand(intN, 1) - 1);
    
    R(1)=-1; % Assign boundary charges.
    R(intN)=1;
   
% Calculate the charges of N forces using Coulomb's Total Force.
    q_zero = input('Enter charge amount: ');
    constant=1;
    En=zeros(N,N);
    q=0.0;
    for i = 1:N
        En=zeros(N,N);
        En = sum((q(i)*(R-R(i)))/(constant*(abs(R-R(i))^3)));
    end
    Fx=q_zero*En;

Subject: ??? Error using ==> mpower

From: Husam Aldahiyat

Date: 2 Jan, 2009 15:17:02

Message: 2 of 5

"Sid Hayes" <sid.hayes@hotmail.com> wrote in message <gjlaoc$1r3$1@fred.mathworks.com>...
> Hi
>
> I am trying to implement a formula for total force. Its seems to give me a run-time error during execution.
>
> the error is:
> ??? Error using ==> mpower
> Matrix must be square.
>
> Error in ==> TFalgorithm at 26
> En = sum((q(i)*(R-R(i)))/(constant*(abs(R-R(i))^3)));
>
> my algorithm is:
> clear all;
> % User to enter number of charges (N) to be placed on rod.
> N=input('Enter number of charges: ');
>
> % Position N charges on the rod randomly.
> intN=int32(N);
> % Get the random numbers, and sort them.
> R = sort(2 * rand(intN, 1) - 1);
>
> R(1)=-1; % Assign boundary charges.
> R(intN)=1;
>
> % Calculate the charges of N forces using Coulomb's Total Force.
> q_zero = input('Enter charge amount: ');
> constant=1;
> En=zeros(N,N);
> q=0.0;
> for i = 1:N
> En=zeros(N,N);
> En = sum((q(i)*(R-R(i)))/(constant*(abs(R-R(i))^3)));
> end
> Fx=q_zero*En;

Use '.^' instead of '^'?

Subject: ??? Error using ==> mpower

From: Sid Hayes

Date: 2 Jan, 2009 15:34:01

Message: 3 of 5

Thanks!

Subject: plz help-me/advise-me on my algorithm!

From: Sid Hayes

Date: 2 Jan, 2009 15:56:01

Message: 4 of 5

Hi

Im having problems implementing my algorithm. All i want to implement is the formula:

% q_zero is just a scalar number, assume scalars q(i)'s all equal to one.
% c=constant scalar.
% R is a vector. i.e, the random charges on a rod, where the force is to be computed % between the cahrges.

F=q_zero*E

where E= sum(for i=1:N) q(i)*(R-R(i))/c*(abs(R-R(i)).^3)

Can someone please help me, or advise me on a better way to implement this?

Warm Regards
Sid

Subject: plz help-me/advise-me on my algorithm!

From: Matt

Date: 2 Jan, 2009 17:06:01

Message: 5 of 5

"Sid Hayes" <sid.hayes@hotmail.com> wrote in message <gjldeh$709$1@fred.mathworks.com>...
> Hi
>
> Im having problems implementing my algorithm. All i want to implement is the formula:
>
> % q_zero is just a scalar number, assume scalars q(i)'s all equal to one.
> % c=constant scalar.
> % R is a vector. i.e, the random charges on a rod, where the force is to be computed % between the cahrges.
>
> F=q_zero*E
>
> where E= sum(for i=1:N) q(i)*(R-R(i))/c*(abs(R-R(i)).^3)
>
> Can someone please help me, or advise me on a better way to implement this?


Are you sure you don't mean

E= sum(for i=1:N) q(i)*(R-R(i))/( c*abs(R-R(i)).^3 ); %Notice where parentheses are now in the denominator

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us