integral and derivatives of a function
이전 댓글 표시
trying to attain the integral and derivative of a function, and then plot the derivative
ya(x)=sin^3((2/(x+2))-3)
i saved the function as file a3
function [ya] = a3(x)
ya = (sin((2./(x+2))-3)).^3;
end
then on a seperate file my code is:
clc
clear
inta3=integral(@a3,0,5)
x=0:0.1:5
Ax=a3(x)
diffa3= diff(Ax)/x
figure
plot(x,Ax)
hold on
xlabel('X')
ylabel('Y')
title('Derivative of 3a')
in the command window it says this when i run the code:
Error using /
Matrix dimensions must agree.
Error in a4 (line 10)
diffa3= diff(Ax)/x
i think th integral part is fine its just the derivative part
채택된 답변
추가 답변 (1개)
madhan ravi
2019년 1월 26일
편집: madhan ravi
2019년 1월 26일
clc
clear
inta3=integral(@a3,0,5);
x=0:0.1:5
Ax=a3(x);
diffa3= diff(Ax)./0.01;
% missed it-----^ ^^^^----- should be the step size
figure
plot(x(1:numel(Ax)),Ax) % look here
hold on
xlabel('X')
ylabel('Y')
title('Derivative of 3a')
function ya = a3(x)
ya = (sin((2./(x+2))-3)).^3;
end
카테고리
도움말 센터 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!