help with Integral function

조회 수: 1 (최근 30일)
Francis Segesman
Francis Segesman 2021년 9월 9일
댓글: Sulaymon Eshkabilov 2021년 9월 9일
% Please enter your name inside the single quotes in the next line
name = 'Segesman, Francis'; % Last Name, First Name
% Define unknowns and variables of integration
syms v1; % Unknown
syms t v; % Variables of integration
% Given
a = 20*t; % [m/s^2]
t0 = 0; t1 = 3; % [s]
v0 = -10; % [m/s]
% Solve
eqn = integral((a),t0,t1)== integral(dv,v0,v1) % Define the equation
Error using integral (line 81)
First input argument must be a function handle.
v1 = solve(eqn,v1) % Use solve to solve for v1
% If you have trouble, you may refer to WK1MATLAB1.
% Display
disp('You should get: The velocity at t=3 s is 80.00 m/s.');
fprintf('The velocity at t=3 s is %3.2f m/s.\n',v1);
fprintf('\n');
nameInfo = isempty(name);
if (nameInfo==1)
disp('Please enter your name in Line 2.');
end;
when I run this program it gives me the error "Invalid expression. When calling a function or indexing a variable,
use parentheses. Otherwise, check for mismatched delimiters." but my parenteses are all matched up. have i jsut missed something?

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 9월 9일
There are a couple of errs in your code. Here is the corrected code:
% Please enter your name inside the single quotes in the next line
name = 'Segesman, Francis'; % Last Name, First Name
% Define unknowns and variables of integration
syms v1 % Unknown
syms t v % Variables of integration.
% Given
% Note how the function handle is created with @:
a = @(t)20*t; % [m/s^2]
t0 = 0; t1 = 3; % [s]
v0 = -10; % [m/s]
dv=@(v)1;
% Solve
% Note how the equation is set up with a symbolic var v1 in the 2nd half of the equation:
eqn = integral(a,t0,t1)- (v1-v0)==0
v1 = solve(eqn,v1) % Use solve to solve for v1
% If you have trouble, you may refer to WK1MATLAB1.
% Display
disp('You should get: The velocity at t=3 s is 80.00 m/s.');
fprintf('The velocity at t=3 s is %3.2f m/s.\n',v1);
fprintf('\n');
nameInfo = isempty(name);
if (nameInfo==1)
disp('Please enter your name in Line 2.');
end
  댓글 수: 2
Francis Segesman
Francis Segesman 2021년 9월 9일
편집: Francis Segesman 2021년 9월 9일
Thank you for this, incorperated that a "a = @(t)20*t;" and the "dv=@(v)1;" and it worked like a charm
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 9월 9일
Most welcome!

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

추가 답변 (1개)

Matt J
Matt J 2021년 9월 9일
편집: Matt J 2021년 9월 9일
I don't think you've posted the version of the code that you are running. As you can see above (I have edited and run your code using the Matlab Online engine) it produces different errors from what you claim.
Regardless, the integral() command is not for symbolic functions. You need to use int().

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by