フィルターのクリア

help with Integral function

1 回表示 (過去 30 日間)
Francis Segesman
Francis Segesman 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 Center および File ExchangeNumber Theory についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by