How can I use arrayfun and integral as anonymous function?

4 visualizaciones (últimos 30 días)
work wolf
work wolf el 10 de Jun. de 2021
Comentada: work wolf el 11 de Jun. de 2021
t=0:0.1:1;
v=0.2;
fun1=@(s,t) s .* exp(-s).* ( (t-s) .^(v-1) ) ;
%gex= @(t) arrayfun(@(t) integral (@(s) fun1(s,t) ,0,t), t);
if t==0
gex= @(t) 0;
else
gex= @(t) arrayfun(@(t) integral (@(s) fun1(s,t) ,0,t), t);
end
How do I exclude input
t=0
and make it into a new value inside the matrix namely, gex, i.e, gives
gex(t)
as one matrix and set the value of
gex(t(1))=0
in same time?
  2 comentarios
David Hill
David Hill el 10 de Jun. de 2021
I have no idea what you are trying to do. What is the array t?
work wolf
work wolf el 10 de Jun. de 2021
Editada: work wolf el 10 de Jun. de 2021
I edited a question to define t

Iniciar sesión para comentar.

Respuesta aceptada

David Hill
David Hill el 10 de Jun. de 2021
I am doing a little guessing. I assume you want to integrate with respect to s (0,t) then look at t from 0:0.1:1.
syms s t
v=0.2;
fun=s*exp(-s)*(t-s)^(v-1);
fun1=int(fun,s,0,t);
n=0:.1:1;
for k=1:length(n)
b(k)=vpa(subs(fun1,t,n(k)));
end
  3 comentarios
David Hill
David Hill el 10 de Jun. de 2021
Works, but does not get exact answers. Answers good for several decimal places.
v=0.2;
t=0:.1:1;
fun1=zeros(1,length(t));
for k=2:length(t)
fun=@(s)s.*exp(-s).*(t(k)-s).^(v-1);
fun1(k)=integral(fun,0,t(k));
end
work wolf
work wolf el 11 de Jun. de 2021
Thanks, do you have another idea to exclude zero, i.e output NaN, as anonymous function?
The problem when substitution zero, gives NaN. That is, (t-s).^(v-1) gives (t-s).^(-0.8). So, i am thinking to make two anonymous function, the first, t>0 and another t==0.

Iniciar sesión para comentar.

Más respuestas (1)

Kapil Gupta
Kapil Gupta el 10 de Jun. de 2021
I assume you want to know how you can use integral function as anonymous function. The following MATLAB Answers link has a similar query, you can check this out:

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by