In an assignment A(I) = B, the number of elements in B and I must be the same. Error in odev_3_c (line 9) fprime(1)=x.*cos(3*x);

1 view (last 30 days)
clc
clear
format long
x=0:1:4;
fg=x.*(cos(3*x));
% 6 anlamlı basamak için hesaplama
fprime(1)=x.*cos(3*x);
fprime(2)=-6*sin(3*x)-9*x.cos(3*x);
fprime(3)=-27*cos(3*x)+27*x.*sin(3*x);
fprime(4)=108*sin(3*x)+81*x.cos(3*x);
fprime(5)=405*cos(3*x)-243*x.*sin(3*x);
fs1=0;
for i=1:5
fs1=fs1+fprime(i)*x^{i-1}/factorial(i-1);
%bağıl hata hesaplama
if abs((fg-fs1)/fg)<0.5*1e-5
disp('gercek değer:')
fg,
disp('aranan yaklaşık değer:')
fs1,
disp('iterasyon sayısı')
i,
break
end
end

Answers (1)

Geoff Hayes
Geoff Hayes on 7 Nov 2015
Gökhan - if you step through your code using the MATLAB debugger, you will be able to identify the problem. The error message is telling you that you are trying to assign too many elements on the right-hand side of an assignment. Your line of code (and the ones that follow)
fprime(1)=x.*cos(3*x);
is trying to assign five elements to one. Is this the intent? Should fprime be a matrix or an array? Once you determine that, you will need to correct the errors with
6*sin(3*x)-9*x.cos(3*x);
where it should be
6*sin(3*x)-9*x.*cos(3*x);
instead (note the .*).

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!