Borrar filtros
Borrar filtros

help with Integral function

1 visualización (últimos 30 días)
Francis Segesman
Francis Segesman el 9 de Sept. de 2021
Comentada: Sulaymon Eshkabilov el 9 de Sept. de 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?

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 9 de Sept. de 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 comentarios
Francis Segesman
Francis Segesman el 9 de Sept. de 2021
Editada: Francis Segesman el 9 de Sept. de 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 el 9 de Sept. de 2021
Most welcome!

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
Matt J el 9 de Sept. de 2021
Editada: Matt J el 9 de Sept. de 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().

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by