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:
FUNCTION INTEGRATION WITH RANDOM NUMBER

Subject: FUNCTION INTEGRATION WITH RANDOM NUMBER

From: george veropoulos

Date: 3 Apr, 2014 09:25:12

Message: 1 of 3

Dear friends

i have a function F(x, E0, theta)
E0 , theta are random number , i use the random function


E0=random('unif',0,E0max,[1,10000]);
thetae=random('unif',0,2*pi,[1,10000]);

I want to integrate the f over x and make h histogram
but i have problem with dimension

i use the code

E0=random('unif',0,E0max,[1,10000]);

thetae=random('unif',0,2*pi,[1,10000]);
%sources terms
f1=@(x)F(r,E0,thetae);
Es=integral(f1,0,s)

the matllab give the error

Error using .*
Matrix dimensions must agree.
in F

Subject: FUNCTION INTEGRATION WITH RANDOM NUMBER

From: Steven Lord

Date: 3 Apr, 2014 13:41:35

Message: 2 of 3


"george veropoulos" <veropgr@yahoo.gr> wrote in message
news:lhj9do$ka6$1@newscl01ah.mathworks.com...
> Dear friends
> i have a function F(x, E0, theta)
> E0 , theta are random number , i use the random function
>
>
> E0=random('unif',0,E0max,[1,10000]);
> thetae=random('unif',0,2*pi,[1,10000]);
>
> I want to integrate the f over x and make h histogram but i
> have problem with dimension
> i use the code
> E0=random('unif',0,E0max,[1,10000]);
>
> thetae=random('unif',0,2*pi,[1,10000]);
> %sources terms
> f1=@(x)F(r,E0,thetae);

As written F is not a function of x. Did you actually intend the r that you
specified as the first input to be x?

> Es=integral(f1,0,s)

Your function is not written so it satisfies the requirement on the FUN
input argument for INTEGRAL.

http://www.mathworks.com/help/matlab/ref/integral.html

"...the function y = fun(x) must accept a vector argument, x, and return a
vector result, y."

I'm guessing you're trying to multiply x and either E0 or thetae
elementwise. That would work if x is scalar, but INTEGRAL doesn't call your
function with a scalar by default.

If your F function is supposed to return a vector of values when given a
scalar (say a 1-by-10000 vector) then use the ArrayValued flag.

"If you set the 'ArrayValued' option to true, fun must accept a scalar and
return an array of fixed size."

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: FUNCTION INTEGRATION WITH RANDOM NUMBER

From: george veropoulos

Date: 3 Apr, 2014 16:38:08

Message: 3 of 3

"george veropoulos" <veropgr@yahoo.gr> wrote in message <lhj9do$ka6$1@newscl01ah.mathworks.com>...
> Dear friends
>
> i have a function F(x, E0, theta)
> E0 , theta are random number , i use the random function
>
>
> E0=random('unif',0,E0max,[1,10000]);
> thetae=random('unif',0,2*pi,[1,10000]);
>
> I want to integrate the f over x and make h histogram
> but i have problem with dimension
>
> i use the code
>
> E0=random('unif',0,E0max,[1,10000]);
>
> thetae=random('unif',0,2*pi,[1,10000]);
> %sources terms
> f1=@(x)F(r,E0,thetae);
> Es=integral(f1,0,s)
>
> the matllab give the error
>
> Error using .*
> Matrix dimensions must agree.
> in F

tnank you Lord
i find a solution
the integral function of matlab have a flag
ArrayValued',true indicates that the integrand is an array-valued function.
this work.....

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