How to find double integral in Matlab to the following code
4 views (last 30 days)
Show older comments
norh hameed
on 26 Jul 2020
Commented: norh hameed
on 27 Jul 2020
I have the following code, I have a problem to solve it, please i need help
syms s t
a=0.1;b=0.4;
Rs=-log(s);
Ws=vpa([int(log(s)*log(s)*Rs,s,a,b), -int(log(s)*Rs,s,a,b), -2*int(log(s)*cos(2*pi*s)*Rs,s,a,b); ...
-int(log(s)*Rs,s,a,b), int(Rs,s,a,b), 2*int(cos(2*pi*s)*Rs,s,a,b); ...
-2*int(log(s)*cos(2*pi*s)*Rs,s,a,b), 2*int(cos(2*pi*s)*Rs,s,a,b), 4*int(cos(2*pi*s)*cos(2*pi*s)*Rs,s,a,b)]);
W11=inv(Ws);
w1 = W11(:,1);
g(s)=[-log(s);1;2*cos(2*pi*s)];
g(t)=[-log(t);1;2*cos(2*pi*t)];
Gs=((w1)'*g(s));
Gt=((w1)'*g(t));
fin = @(s,t) Gs.*Gt.*Rs.*Rt.*(min(1-s,1-t)-((1-s).*(1-t)));
MM=integral2(fin,0.1,0.4,0.1,0.4)
The problem in the min(1-s,1-t)-((1-s).*(1-t))
Thank you in advance
3 Comments
Accepted Answer
Walter Roberson
on 27 Jul 2020
syms s t v
Q = @(v) sym(v);
a = Q(0.1);
b = Q(0.4);
Rs = -log(s);
Rt = -log(t);
Pi = Q(pi);
Int = @vpaintegral;
Ws = ([Int(log(s)*log(s)*Rs,s,a,b), -Int(log(s)*Rs,s,a,b), -2*Int(log(s)*cos(2*Pi*s)*Rs,s,a,b); ...
-Int(log(s)*Rs,s,a,b), Int(Rs,s,a,b), 2*Int(cos(2*Pi*s)*Rs,s,a,b); ...
-2*Int(log(s)*cos(2*Pi*s)*Rs,s,a,b), 2*Int(cos(2*Pi*s)*Rs,s,a,b), 4*Int(cos(2*Pi*s)*cos(2*Pi*s)*Rs,s,a,b)]);
W11 = inv(Ws);
w1 = W11(:,1);
g(v) = [-log(v);1;2*cos(2*Pi*v)];
Gs=((w1)'*g(s));
Gt=((w1)'*g(t));
Min = @(a,b) piecewise(a<=b, a, b);
fin = Gs.*Gt.*Rs.*Rt.*(Min(1-s,1-t)-((1-s).*(1-t)));
MM = Int(Int(fin,s,Q(0.1),Q(0.4)),t,Q(0.1),Q(0.4));
disp(MM)
Your Gs and Gt are separable and could be calculated independently if not for the (Min(1-s,1-t)-((1-s).*(1-t))) part .
5 Comments
Walter Roberson
on 27 Jul 2020
Yes it does. If you were to upgrade to even just one release after what you have now, you would get much faster results.
You could probably improve performance by splitting into two cases at the boundary of the two expressions being min(). If you were to do that then you could use matlabFunction() and integral2()
More Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!