I dont get why I am encountering an error message when running this code.

1 visualización (últimos 30 días)
Shashwat Roy
Shashwat Roy el 27 de Sept. de 2022
Comentada: VBBV el 27 de Sept. de 2022
I want to find the integral for a function with variable limit and plot it.
This is the error I get:
Error using integralCalc/finalInputChecks
Input function must return 'double' or 'single' values. Found 'sym'.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
Error in rough>@(x)integral(@(t)v_t*(1-exp(expo1)+v_i*(1+exp(expo2)))./(v_t*(1+exp(expo1))+v_i*(1-exp(expo2))),1,x) (line 6)
ln_scalar = @(x)integral(@(t)v_t*(1-exp(expo1)+v_i*(1+exp(expo2)))./(v_t*(1+exp(expo1))+v_i*(1-exp(expo2))),1,x);
Error in rough>@(x)arrayfun(ln_scalar,x) (line 7)
ln = @(x)arrayfun(ln_scalar,x);
Error in rough (line 9)
plot(x,ln(x))
%v_t=20;
%v_i=1;
%g=10;
%expo1=-2*g*t./v_t;
%expo2=-2*g*t./v_i;
%function I want to integrate and plot:v_t*(1-exp(expo1)+v_i*(1+exp(expo2)))./(v_t*(1+exp(expo1))+v_i*(1-exp(expo2)))
%My code:
v_t=20;
v_i=1;
g=10;
expo1=-2*g*t./v_t;
Unrecognized function or variable 't'.
expo2=-2*g*t./v_i;
ln_scalar = @(x)integral(@(t)v_t*(1-exp(expo1)+v_i*(1+exp(expo2)))./(v_t*(1+exp(expo1))+v_i*(1-exp(expo2))),1,x);
ln = @(x)arrayfun(ln_scalar,x);
x = linspace(0.02,10,100);
plot(x,ln(x))

Respuestas (1)

VBBV
VBBV el 27 de Sept. de 2022
%v_t=20;
%v_i=1;
%g=10;
%expo1=-2*g*t./v_t;
%expo2=-2*g*t./v_i;
%function I want to integrate and plot:v_t*(1-exp(expo1)+v_i*(1+exp(expo2)))./(v_t*(1+exp(expo1))+v_i*(1-exp(expo2)))
%My code:
v_t=20;
v_i=1;
g=10;
t = 2;
expo1=-2*g*t./v_t;
expo2=-2*g*t./v_i;
ln_scalar = @(x)integral(@(t) v_t*(1-exp(expo1)+v_i*(1+exp(expo2)))./(v_t*(1+exp(expo1))+v_i*(1-exp(expo2))),1,x,'ArrayValued',1);
ln = @(x)arrayfun(ln_scalar,x);
x = linspace(0.02,10,100);
plot(x,ln(x))
  1 comentario
VBBV
VBBV el 27 de Sept. de 2022
Define t first before evaluating integral
t = 2;
and set Arrayvalued option to true in integral function
ln_scalar = @(x)integral(@(t) v_t*(1-exp(expo1)+v_i*(1+exp(expo2)))./(v_t*(1+exp(expo1))+v_i*(1-exp(expo2))),1,x,'ArrayValued',1);

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by