f(x)=3x^3-5x^2+3x-7=0
Show older comments
%fx=3x^3-5x^2+5x-7
%fdx=9x^2-10x+3
x(1);
kk(1)=1;
for k=1:100;
fx=3x(k)^3-5x(k)^2+3(k)-7;
fdx=9x(k)^2-10x(k)+3;
h=-fx/fdx;
x(k+1)=x(k)+h;
kk(k+1)=k+1;
if abx(h)<.0000001
break,end
end
disp([kk1'x'])
is it correct program...can you please check with your matlab program.my matlab getting some problem so that i ask you to just check and run for me.inform me the result...
Answers (2)
Guillaume
on 17 Oct 2016
0 votes
I can tell you the result without even trying to run your code. it's going to error with Unexpected MATLAB expression on fx = 3x....
Perhaps you meant fx = 3*x...
Also, note that the line x(1); does absolutely nothing. Maybe you meant to assign a value to it?
1 Comment
Jobayer Rahman
on 17 Oct 2016
x(1) = 0; % assuming x(1) = 0
kk(1)=1;
for k=1:100;
fx=3*x(k)^3-5*x(k)^2+3*x(k)-7; % use multplication operator for products in each terms
fdx=9*x(k)^2-10*x(k)+3; % use multplication operator for products in each terms
h=-fx/fdx;
x(k+1)=x(k)+h;
kk(k+1)=k+1;
if abs(h)<.0000001 % there is no abx function in Matlab, it must be abs
break;
end
end
disp([kk' x']) % There is no kk1 array, instead it is kk as calculated inside the loop
plot(kk,x); grid ; xlabel('Iteration [-]'); ylabel('x')
Categories
Find more on Performance and Memory 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!