help with Integral function

1 vue (au cours des 30 derniers jours)
Francis Segesman
Francis Segesman le 9 Sep 2021
% 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?

Réponse acceptée

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 9 Sep 2021
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 commentaires
Francis Segesman
Francis Segesman le 9 Sep 2021
Modifié(e) : Francis Segesman le 9 Sep 2021
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 le 9 Sep 2021
Most welcome!

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 9 Sep 2021
Modifié(e) : Matt J le 9 Sep 2021
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().

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by