Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
% 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 Kommentare
Steven Lord
Steven Lord am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ridwan Alam
Ridwan Alam am 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);

Weitere Antworten (1)

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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by