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

조회 수: 1 (최근 30일)
Shashwat Roy
Shashwat Roy 2022년 9월 27일
댓글: VBBV 2022년 9월 27일
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))

답변 (1개)

VBBV
VBBV 2022년 9월 27일
%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
VBBV
VBBV 2022년 9월 27일
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);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by