thank you very much if anyone can help me.
so, I need to create a loop that calculates integrals at each point. Say I have the following function handle
D = @(x,y) x.*(Z(x,y).^2);
from that function, I need to calculate a double integral and create the following loop
int1 = @(y) integral(@(x)D(x,y),x1,x2,'ArrayValued',true);
int2 = integral(@(y)int1,y1,y2,'ArrayValued',true);
c1 = int2./g % g is a scalar number
int11 = @(y) integral(@(x)D(x,y),x2,x3,'ArrayValued',true);
int22 = integral(@(y)int11,y1,y2,'ArrayValued',true);
c11 = int22./g % g is a scalar number
int111 = @(y) integral(@(x)D(x,y),x3,x4,'ArrayValued',true);
int222 = integral(@(y)int111,y1,y2,'ArrayValued',true);
c111 = int222./g % g is a scalar number
.
.
.
i'm trying to do like this
x = 1:0.1:5
for i = 1:length(x)
D = @(x,y) x.*(Z(x,y).^2);
int1(i) = @(y) integral(@(x)D(x,y),x(i),x(i)+0.5,'ArrayValued',true);
int2(i) = integral(@(y)int1(i),y1,y2,'ArrayValued',true);
c = int2(i)./g
end
I need to plot a graph of c versus x

5 件のコメント

darova
darova 2020 年 3 月 6 日
Can you show original equations?
José Anchieta de Jesus Filho
José Anchieta de Jesus Filho 2020 年 3 月 6 日
編集済み: José Anchieta de Jesus Filho 2020 年 3 月 6 日
dF = @(z1,r) 2.*pi.*v.*ro.*(Brt(z1,r).^2).*r; % v , ro are scalar numbers
p1 = @(r) integral(@(z1) dF(z1,r),z0,z0+e,'ArrayValued',true); % e is also a scalar
F = integral(@(r) p1,ri,re,'ArrayValued',true);
c = F./v
this is my equation
José Anchieta de Jesus Filho
José Anchieta de Jesus Filho 2020 年 3 月 6 日
that's my role in response to z0. what I need is for it to be calculated with the z0 varying
z0 = 0:0.001:0.03
for each variation of z0, I will have a new p1, a new F and, consequently, a new c. I want to plot a graph of z0 versus c
Walter Roberson
Walter Roberson 2020 年 3 月 6 日
p1 = @(r) integral(@(z1) dF(z1,r),z0,z0+e,'ArrayValued',true); % e is also a scalar
p1 is a function handle.
F = integral(@(r) p1,ri,re,'ArrayValued',true);
@( r) p1 is a handle to an anonymous function that accepts a single parameter and ignores the parameter and returns the function handle p1. You should be just using
F = integral(p1,ri,re,'ArrayValued',true);
José Anchieta de Jesus Filho
José Anchieta de Jesus Filho 2020 年 3 月 6 日
thank you very much, I will modify. But, you know how to change the function to calculate the integral for various values of z0

サインインしてコメントする。

 採用された回答

darova
darova 2020 年 3 月 6 日

0 投票

Here is a shot
z0 = 0:0.001:0.03;
c = z0*0;
Brt = @(z1,r) z1+r;
e = 0.1;
ri = 0;
re = 1;
ro = 15;
v = 2;
dF = @(z1,r) 2.*pi.*v.*ro.*(Brt(z1,r).^2).*r; % v , ro are scalar numbers
for i = 1:length(z0);
F = integral2(dF,z0(i),z0(i)+e,ri,re);
c(i) = F./v;
end
plot(z0,c)

3 件のコメント

José Anchieta de Jesus Filho
José Anchieta de Jesus Filho 2020 年 3 月 6 日
I tried, but an error appears. The Brt function (z1, r), it is a little complicated, as it was calculated with numeric integrals. I can't explain it very well, but this example (4-D Integral of Sphere) is similar to the calculation done for her
I can't calculate the integral, in this case, p1, without adding 'Array Valued', because of the integrations I did earlier.
I really appreciate your help and, unfortunately, the code didn't work
darova
darova 2020 年 3 月 6 日
Please attach the whole code
José Anchieta de Jesus Filho
José Anchieta de Jesus Filho 2020 年 3 月 7 日
I thank you so much for your help. I changed the code a little and managed to make it work. Thank you
for i = 1:length(z0)
P = @(r) integral(@(z1) dF(z1,r),z0(i),z0(i)+e,'ArrayValued',true);
F = integral(P,ri,re,'ArrayValued',true);
c(i) = F./v;
end
plot(z0,c)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by