error in integration of function

>> K=@(t,s)(12.*sin(2.*pi.*s).*cos(2.*pi.*s).*(3.*(sin(2.*pi.*t)-sin(2.*pi.*s))-2.*(cos(2.*pi.*t)-cos(2.*pi.*s))))./(sqrt(16.*pi.*pi+20.*pi.*pi.*cos(2.*pi.*s).^2)*(8+5.*sin(2.*pi.*t).^2+5.*sin(2.*pi.*s).^2-8.*cos(2.*pi.*(t-s))-10.*sin(2.*pi.*t).*sin(2.*pi.*s)));
this is my function I'm trying to integrate it but I'm getting error
F = @(x)exp(x);
Fp = zeros(N+1,1);
for i=1:N+1
x = (i-1)*h;
syms x s;
Fp(i) = int(24*K(x,s).*F(s),s,0,1);% integrating wrt s
end
I'm trying to integrate it after multiplying with F , N is a given no. we can take 100 for example, h=1/N
But I'm getting following error,
The following error occurred converting from sym to double:
Unable to convert expression into double array.
Error in rjpro (line 15)
Fp(i) = int(24*K(x,s).*F(s),s,0,1);% integrating wrt s

Answers (1)

John D'Errico
John D'Errico on 27 Mar 2022
Edited: John D'Errico on 27 Mar 2022
You don't understand.
You define x. i and N are numbers.
i = 1;
N = 100;
h = 1/N;
x = (i-1)*h;
What is x now? A number. Great. It is well defined. It is a double.
whos x
Then what do you do?
syms x s;
x
whos x
Do you see that now x is no longer the numeric value you gave it?
syms does not just take the existing value, and make it a sym, with that numeric value. If overwrites the existigng value of x.
K=@(t,s)(12.*sin(2.*pi.*s).*cos(2.*pi.*s).*(3.*(sin(2.*pi.*t)-sin(2.*pi.*s))-2.*(cos(2.*pi.*t)-cos(2.*pi.*s))))./(sqrt(16.*pi.*pi+20.*pi.*pi.*cos(2.*pi.*s).^2)*(8+5.*sin(2.*pi.*t).^2+5.*sin(2.*pi.*s).^2-8.*cos(2.*pi.*(t-s))-10.*sin(2.*pi.*t).*sin(2.*pi.*s)));
F = @(x)exp(x);
Fp = zeros(N+1,1);
N = 100;
h = 1/N;
i = 2;
x = (i-1)*h;
syms s
int(24*K(x,s).*F(s),s,0,1)
ans =
int(-(144*exp(s)*cos(2*pi*s)*sin(2*pi*s)*(2*cos(pi/50) - 3*sin(pi/50) - 2*cos(2*pi*s) + 3*sin(2*pi*s)))/((4*pi^2 + 5*pi^2*cos(2*s*pi)^2)^(1/2)*(5*sin(pi/50)^2 - 10*sin(pi/50)*sin(2*pi*s) - 8*cos(2*pi*(s - 1/100)) + 5*sin(2*pi*s)^2 + 8)), s, 0, 1)
Given all that, can int solve the problem at all? It appears not to be the case.
Then I tried the numerical integration tool. It too fails.
vpaintegral(24*K(x,s).*F(s),s,0,1)
Error using sym/vpaintegral (line 204)
Failed precision goal. Try using 'MaxFunctionCalls'.
And that is not unexpected.

1 Comment

ka
ka on 27 Mar 2022
Edited: ka on 27 Mar 2022
Does it mean that we can't integrate this function at all?@John D'Errico

Sign in to comment.

Products

Release

R2020a

Asked:

ka
on 27 Mar 2022

Edited:

ka
on 27 Mar 2022

Community Treasure Hunt

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

Start Hunting!