Problem with derivative function syntax
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ok so basically what I'm doing here is trying to graph a function and its derivative in matlab. This is what I have:
clear; clc; close all; x=(-2:0.1:4); y=x.^3-2*x.^2-10*sind(x).^2-exp(0.9*x); yd=3*x.^2-4*x-20*sind(x)*cosd(x)-0.9*exp(0.9*x); plot(x,y,x,yd,'--'); xlabel('X Values'); ylabel('Y Values'); legend('function', 'first derivative')
There are no errors in my original function. But for some reason, the derivative function keeps giving me an error. It says "Error using * Inner matrix dimensions must agree. If anyone can help me fix the syntax, it would be greatly appreciated!
0 Kommentare
Antworten (1)
Star Strider
am 21 Okt. 2014
Since sind and cosd are both functions of row vector ‘x’, they produce row vectors as output. To multiply them, you need to vectorise them, replacing (*) with (.*):
yd=3*x.^2-4*x-20*sind(x).*cosd(x)-0.9*exp(0.9*x);
With that change, it works!
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!