How to create array while using integral function?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Following is the code, there are parameters - b,c,gama1,sigma. And r that is the radius of the sphere is varing, also the time is varying. I want to get at each radial point at given time the value of I(integral) What am I doing is wrong?
K1=6;%(W/m.K)Thermal conductivity of Fe3O4 nanoparticle
K2=0.598; %Thermal conductivity of water-https://thermtest.se/thermal-conductivity-of-water
k1= 1.82E-06; %(m^2/s) Diffusivity of Fe3O4 nanoparticle
k2=2.29e-9; %at 25C (m^2/s) diffusivity of water- https://en.wikipedia.org/wiki/Molecular_diffusion
a=15e-9; %radius of nanoparticle
Vol= (4/3)*3.14*a^3;%Volume of nanoparticle
A=8.68E-05; %(W)heatproduced/ unit volume
b=(K2/K1)*((k1/k2)^1/2);
r=linspace(15e-9,17e-9,10);
c=1-(K2/K1);
t=linspace(1e-12,100e-12,10);
gama1=(a^2)/k1;
sigma=((r/a)-1)*((k1/k2)^1/2);
for t = 1e-12:100e-12
r = 15e-9:17e-9;
fun = @(y,gama1,sigma,b,c,t) ((exp(((-y.^2).*t)./gama1)).*(sin(y)-(y.*cos(y))).*((b.*y.*sin(y).*cos(sigma.*y))-((c.*sin(y)-y.*cos(y)).*sin(sigma.*y))))./((y.^3).*((((c.*sin(y))-(y.*cos(y))).^2)+((b.^2).*(y.^2).*(sin(y).^2))));
I=integral(@(y) fun(y,gama1,sigma,b,c,t),0,inf); %integration wrt y with other constants
end
0 Kommentare
Antworten (2)
VBBV
am 24 Apr. 2023
Bearbeitet: VBBV
am 24 Apr. 2023
K1=6;%(W/m.K)Thermal conductivity of Fe3O4 nanoparticle
K2=0.598; %Thermal conductivity of water-https://thermtest.se/thermal-conductivity-of-water
k1= 1.82E-06; %(m^2/s) Diffusivity of Fe3O4 nanoparticle
k2=2.29e-9; %at 25C (m^2/s) diffusivity of water- https://en.wikipedia.org/wiki/Molecular_diffusion
a=15e-9; %radius of nanoparticle
Vol= (4/3)*3.14*a^3;%Volume of nanoparticle
A=8.68E-05; %(W)heatproduced/ unit volume
b=(K2/K1)*((k1/k2)^1/2);
r=linspace(15e-9,17e-9,10);
c=1-(K2/K1);
t=linspace(1e-12,100e-12,10);
gama1=(a^2)/k1;
sigma=((r/a)-1)*((k1/k2)^1/2);
syms y
for J = 1:length(sigma)
for K = 1:length(t)
fun = ((exp(((-y.^2).*t(K))./gama1)).*(sin(y)-(y.*cos(y))).*((b.*y.*sin(y).*cos(sigma(J).*y))-((c.*sin(y)-y.*cos(y)).*sin(sigma(J).*y))))./((y.^3).*((((c.*sin(y))-(y.*cos(y))).^2)+((b.^2).*(y.^2).*(sin(y).^2))));
I(K,J)= vpaintegral(fun,y,[0,Inf]); %integration wrt y with other constants
end
end
I = (vpa(I,15))
0 Kommentare
Dyuman Joshi
am 24 Apr. 2023
%Formatting your code properly is a good coding practice
K1=6; %(W/m.K)Thermal conductivity of Fe3O4 nanoparticle
K2=0.598; %Thermal conductivity of water-https://thermtest.se/thermal-conductivity-of-water
k1=1.82E-06; %(m^2/s) Diffusivity of Fe3O4 nanoparticle
k2=2.29e-9; %at 25C (m^2/s) diffusivity of water- https://en.wikipedia.org/wiki/Molecular_diffusion
a=15e-9; %radius of nanoparticle
Vol=(4/3)*3.14*a^3; %Volume of nanoparticle
A=8.68E-05; %(W)heatproduced/ unit volume
b=(K2/K1)*((k1/k2)^1/2);
r=linspace(15e-9,17e-9,10);
c=1-(K2/K1);
t=linspace(1e-12,100e-12,10);
gama1=(a^2)/k1;
sigma=((r/a)-1)*((k1/k2)^1/2);
%preallocation
I = zeros(numel(t),numel(r));
%Function to integrate
fun = @(y,t) ((exp(((-y.^2).*t)./gama1)).*(sin(y)-(y.*cos(y))).*((b.*y.*sin(y).*cos(sigma.*y))-((c.*sin(y)-y.*cos(y)).*sin(sigma.*y))))./((y.^3).*((((c.*sin(y))-(y.*cos(y))).^2)+((b.^2).*(y.^2).*(sin(y).^2))));
for k = 1:numel(t)
%Pass the value of t(k)
I(k,:)=integral(@(y) fun(y,t(k)),0,inf,'ArrayValued',true); %integration wrt y with other constants
end
format long
I
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
