How to solve error A and B must be floating point scalar?

1 view (last 30 days)
I'm trying to integrate a function which is
Below is my code
q=1;
y=10;
v=3.5;
t=1;
z=v*t;
syms pi theta x1 x2
a=-(q*x1*v)/4*pi;
b=(0.5*x1)- (y*cos(theta));
c=(y.^2)+((0.5*x1).^2)+(x1*y*cos(theta));
d=z+(0.5*x2);
e=z-(0.5*x2);
f=(c+(d.^2)).^0.5;
g=(c+(e.^2)).^0.5;
h=@(theta)(b/c)*((d/f)-(e/g));
i=integral(h,0,2*pi);
p=a*i;
I get the error A and B must be floating point scalars. How can I solve this? Many thanks for your help.
p/s: (x1=l) and (x2=w) are the variables that I will optimized using PSO. I will call this function in my PSO code.

Accepted Answer

Ahmet Cecen
Ahmet Cecen on 3 May 2015
You are using the wrong integral function. Symbolic integrals are calculated using 'int' instead. So keep your h as an expression:
h=(b/c)*((d/f)-(e/g));
i=int(h,theta,0,2*pi);
  2 Comments
aisyah johari
aisyah johari on 3 May 2015
Thank you sir,
However, I got a warning explicit integral could not be found so it affects my PSO output. Is there any other way of writing this function?
nafeesa saleh
nafeesa saleh on 3 Apr 2016
Try to calculate int with double. example: double(int(x,0,1))

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!