Effacer les filtres
Effacer les filtres

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

5 vues (au cours des 30 derniers jours)
% 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 commentaires
Steven Lord
Steven Lord le 20 Nov 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.

Connectez-vous pour commenter.

Réponse acceptée

Ridwan Alam
Ridwan Alam le 20 Nov 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);

Plus de réponses (1)

lilo moutila
lilo moutila le 8 Jan 2021
Did you find the loop for this one ?

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by