Azzera filtri
Azzera filtri

I want to integrate a function

2 visualizzazioni (ultimi 30 giorni)
reshma nesargi
reshma nesargi il 28 Dic 2021
Commentato: reshma nesargi il 2 Gen 2022
i want to integrate this function used quad function but giving error
kindly resolve
  2 Commenti
Walter Roberson
Walter Roberson il 28 Dic 2021
Your code is
function Ix = f(x)
global Lz cr2 n1 n2
%wq = x.*x *cr2/(2 * Lz*Lz);
wq = x;
f5 = fbjnn(x,n1,n2);
Ix = (x.^3).*f5;
end
We do not have values for those global variables, and we do not have your fbjnn function, so we are not able to test the code.
What error message is given?
Torsten
Torsten il 28 Dic 2021
Can "fbjnn" handle vector inputs for x ?

Accedi per commentare.

Risposte (5)

reshma nesargi
reshma nesargi il 28 Dic 2021
kindly go through the entire program and help me sought out the problem.
fbjnn is the function written to calculate the formula given in untitled file.

reshma nesargi
reshma nesargi il 28 Dic 2021
the program worked error free from 2,3 days all of a sudden since yesterday it is giving the error like this
not understanding what the problem is
Error using .^
Arrays have incompatible sizes for
this operation.
Error in fbjnn (line 11)
fz = exp(-z).* (z.^k);
Error in f (line 6)
f5 = fbjnn(x,n1,n2);
Error in quad (line 67)
y = f(x, varargin{:});
Error in Bulk (line 32)
Ix = quad('f',0,100);
  1 Commento
Torsten
Torsten il 28 Dic 2021
Modificato: Torsten il 28 Dic 2021
z and k are incompatible in size.
That's why I asked whether fbjnn can deal with vector input. This shows: it can't.
Use "integral" instead of "quad" and call it with the option 'ArrayValued',true :
Ix = quad('f',0,100); -> Ix = integral(@f,0,100,'ArrayValued',true);
Iz = quad('fun',0,100); -> Iz = integral(@fun,0,100,'ArrayValued',true);

Accedi per commentare.


reshma nesargi
reshma nesargi il 28 Dic 2021
Thank you but what is meant by 'ArrayValued' should we give some value there or write as it is what ever you have suggested
  1 Commento
Walter Roberson
Walter Roberson il 29 Dic 2021
'ArrayValued',true is a "name/value pair" that should be written exactly as Torsten showed.

Accedi per commentare.


reshma nesargi
reshma nesargi il 28 Dic 2021
on substituting quad with integral it gave this error
Warning: Minimum step size reached
near x = 6.284. There may be a
singularity, or the tolerances may
be too tight for this problem.
> In integralCalc/checkSpacing (line 467)
In integralCalc/iterateArrayValued (line 215)
In integralCalc/vadapt (line 130)
In integralCalc (line 75)
In integral (line 87)
In Bulk (line 36)
Unable to perform assignment
because the indices on the left
side are not compatible with the
size of the right side.
Error in Bulk (line 59)
cmb(i+1) = (pref *sumn2)/(9*10^11);

Walter Roberson
Walter Roberson il 29 Dic 2021
global Lz cr2 n1 n2
Uh-oh... caution time.
Lz = 1*10^-06;
cr2 = (hc * c)/(ec * b);
Okay, the globals Lz and cr2 are defined.
for i = 0:1:20
t(i+1)=i;
bkt=kB*t(i+1);
Ix = integral(@f, 0, 100, 'arrayvalued', true)
Okay, what does f do?
function Ix = f(x)
global Lz cr2 n1 n2
%wq = x.*x *cr2/(2 * Lz*Lz);
wq = x;
f5 = fbjnn(x,n1,n2);
Ix = (x.^3).*f5;
end
... f uses the global variables n1 and n2 that are not defined.
  3 Commenti
Walter Roberson
Walter Roberson il 1 Gen 2022
Show us the lines that assign values to n1 and n2 in Bulk.
reshma nesargi
reshma nesargi il 2 Gen 2022
N1 and N2 comes in the for loop of the main program Bulk. I was trying to call the quad function outside the for the so may be the value of N1 and N2 were not reaching it. Now i tried calling it with in the for loop it worked.
thankq very much for all your suggestions to get through this.
thanks much

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by