error Conversion to double from function_handle is not possible.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
t = 0:0.01:10;
nt = length(t);
% Inicialización de u y u'
u = zeros(size(t));
p = zeros(1,nt);
for i = 1:nt
p(i) = @(t) (10./(t(i)+1));
u(i) = integral(@(tau) p(t(i)-tau)*h(tau),0,t(i));
end
me aparece el error Conversion to double from function_handle is not possible.
p(i) = @(t) (10./(t(i)+1));
como solucionarlo?
0 commentaires
Réponse acceptée
Star Strider
le 24 Oct 2023
The ‘p’ function was incorrect, and the ‘h’ funciton is completely missing (so I created it).
Try this (with the correct ‘h’ function) —
t = 0:0.01:10;
nt = length(t);
% Inicialización de u y u'
u = zeros(size(t));
p = zeros(1,nt);
p = @(t) (10./(t+1));
h = @(x) x; % Create Function
for i = 1:nt
u(i) = integral(@(tau) p(t(i)-tau).*h(tau),0,t(i));
end
u
.
2 commentaires
Walter Roberson
le 24 Oct 2023
p = zeros(1,nt);
p = @(t) (10./(t+1));
Why bother to initialize p with zeros there?
Star Strider
le 25 Oct 2023
It was initially written as:
p(i) = @(t) (10./(t(i)+1));
and I didn’t catch the preallocation when I corrected the ‘p’ function. (I was concentrating on it and the absent ‘h’ function.)
Plus de réponses (1)
Sulaymon Eshkabilov
le 24 Oct 2023
Here is the corrected solution:
t = 0:0.01:10;
nt = length(t);
% Inicialización de u y u'
u = zeros(size(t));
p = zeros(1,nt);
p = @(t) (10./(t+1));
Pval=p(t);
% Note that your include h() is unknown. Thus it is removed from the
% formulation. Predefine it if it is to be included.
for i = 1:nt
u(i) = integral(@(tau) Pval(i)*(t(i)-tau).*(tau),0,t(i));
end
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!