differentiating function & getting different answer

4 Ansichten (letzte 30 Tage)
Noah Barrow
Noah Barrow am 7 Feb. 2019
Kommentiert: Noah Barrow am 8 Feb. 2019
hey! I was trying to differentiate this function g(x)=3x-1 and despite the fact that I followed the code provided on the matlab website to a "t", the answer I got within matlab was incorrect. I included a link to the example as well as screenshots of the code they provided and how it appears in my command window.
here's how the code appears on the site:
I typed the same code into my command window but got a different answer...
I'm really confused at this point because now whenever I try to differentiate ANY function I get the same answer!
  4 Kommentare
Noah Barrow
Noah Barrow am 7 Feb. 2019
when I type this in it says "diff is a variable"
Noah Barrow
Noah Barrow am 7 Feb. 2019
i'm using 2018b. is the code drastically different?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

James Tursa
James Tursa am 7 Feb. 2019
Bearbeitet: James Tursa am 7 Feb. 2019
Perhaps you are shadowing the MATLAB function diff with a function of your own. Make sure diff is pointing to the MATLAB function.

Noah Barrow
Noah Barrow am 7 Feb. 2019
can you explain what shadowing is? The code I entered in my command window is directly above-does it appear that my "diff" is pointing to the matlab function?
  4 Kommentare
Walter Roberson
Walter Roberson am 8 Feb. 2019
Execute the command
clearvars
and then run your code again. If the same thing happens, then track down where in your code you assign something to a variable named diff and use a different variable name instead.
Noah Barrow
Noah Barrow am 8 Feb. 2019
FIXED!
Thank you so much :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by