How can I convert from syms to double in this code

t=.01:1:100;
for fh=.167
for i=1:length(t)
U=1;
tc(i)=(erfcinv((1-fh)/exp(t(i))))^2;
G(i)=2*sqrt(t(i)/pi)-1+(exp(tc(i))*erfc(t(i)));
syms x
f(i) =(exp(x)*erfc(sqrt(x)))/sqrt(t(i)-x);
A(i)=int(f(i),[0 tc(i)]);
fInt(i) = int(f(i),[0 tc(i)]);
fVpa(i) = vpa(fInt(i))
E(i)=(G(i)+(1-fh)*(U*(t(i)-tc(i))/sqrt(pi))*(2*sqrt(t(i))-2*(1-fh)*sqrt(t(i)-tc(i))-sqrt(pi)*G(i)-fVpa(i)))
end
plot(t,E(i),'*');
end

Réponses (1)

Use Anonymous Functions (link) instead of the Symbolic Math Toolbox for this:
t=.01:1:100;
fh=.167
for i=1:length(t)
U=1;
tc(i)=(erfcinv((1-fh)/exp(t(i))))^2;
G(i)=2*sqrt(t(i)/pi)-1+(exp(tc(i))*erfc(t(i)));
f = @(x) (exp(x).*erfc(sqrt(x)))./sqrt(t(i)-x);
fInt(i) = integral(f, 0, tc(i));
E(i) = (G(i)+(1-fh)*(U*(t(i)-tc(i))/sqrt(pi))*(2*sqrt(t(i))-2*(1-fh)*sqrt(t(i)-tc(i))-sqrt(pi)*G(i)-fInt(i)));
end
plot(t,real(E))
It might be possible to vectorise your code to make it significantly more efficient. Whether that would be worthwhile depends on how frequently you need to run it.
Experiment to get the result you want.

Community Treasure Hunt

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

Start Hunting!

Translated by