t = 0:0.1:2; %h = 0.1%
h = 0.1;y = (-cos(4*t))./4 - 0.5; z = (-cos(0))./4 - 0.5; y1 = diff(y);y2 = diff(y,2);y3 = diff(y,3);y4 = diff(y,4); taylor_y = (z + (h.*y1) + ((h^2/factorial(2)).*y2) + ((h^3/factorial(3)).*y3) + ((h^4/factorial(4)).*y4));fig = figure();set(fig,'color','white');plot(t,y,'LineWidth',2)grid onxlabel('t')ylabel('y')hold onplot(t,taylor_y,'r','LineWidth',2)
MATLAB: I’m trying to do a Taylor series method for the equation y and compare it to the analytical solution. However, I keep getting a matrix dimension error. any help would be much appreciated.
differentiationMATLABtaylor series
Best Answer