Integrating a function with one of the limits a matrix

2 vues (au cours des 30 derniers jours)
Alyssa Pope
Alyssa Pope le 3 Avr 2021
Commenté : darova le 4 Avr 2021
Hi, just needing some help on integrating this function. I have a function that I'm trying to integrate in terms of y, and one of the bounds on the integral is a matrix that I also calculate within the code. Here is my current code:
r = 350;
S = 0.001;
T = 2400;
t = [1:1:100];
u = ((r^2)*S)./(4*T.*t);
syms y
f = exp(-y)./(y);
integralCalculated = integral(@(y)exp(-y)./(y),u,inf);
So the idea is that I'm integrating from u to infinity where u has 100 components, so that I'll get an output of a matrix that also has 100 values. I get the error that A and B must be floating point scalars, and I've seen some threads that use arrayfun but wasn't clear on how it applies to the function I'm using. Thanks for any help.

Réponse acceptée

darova
darova le 4 Avr 2021
Why don't just use for loop?
integralCalculated = zeros(size(u));
for i = 1:length(u)
integralCalculated(i) = integral(@(y)exp(-y)./(y),u(i),inf);
end
  2 commentaires
Alyssa Pope
Alyssa Pope le 4 Avr 2021
That worked! Thank you very much!
darova
darova le 4 Avr 2021
my pleasure

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by