Determine first and second derivatives, without using builtin diff function, using forward differencing with 0 dx error

17 visualizaciones (últimos 30 días)
% Set the range of x values for the function
dx = 0.1;
x = 0:dx:8;
% calculates the value of f using a given function
f = Wave1(x);
% Initialize the derivative vectors as nan arrays the same size as x.
% You must keep the variable names "dfdx" and "d2fdx2"
dfdx =
d2fdx2 =
% Use a loop to find the first derivatives (but not the built in diff() function).
% You may also delete the loop structure beginning and find the derivative using vector operations
for i =
end
% Find the second derivative.
for i =
end
  2 comentarios
Steven Lord
Steven Lord el 20 de Nov. de 2019
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance. The code you've posted so far seems like a framework that your professor has given you where he or she expects you to fill in a few steps.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

Iniciar sesión para comentar.

Respuesta aceptada

Ridwan Alam
Ridwan Alam el 20 de Nov. de 2019
dfdx = zeros(size(f));
d2fdx2 = zeros(size(f));
dfdx(2:end) = f(2:end)-f(1:end-1);
d2fdx2(2:end) = dfdx(2:end) - dfdx(1:end-1);

Más respuestas (1)

lilo moutila
lilo moutila el 8 de En. de 2021
Did you find the loop for this one ?

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by