help with Integral function

1 次查看(过去 30 天)
% 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
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

请先登录,再进行评论。

更多回答(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