Hello,
I'm trying to make function functions, but I have an error in the last row and I don't know that's wrong:
clc;close all;clear all;syms x;fun=@(x)-0.0641*x^3+1.0889*x^2-3.8260*x+0.6364;n=input('Enter the number of decimal places:');x0 = input('Enter the intial approximation:');[t]=F[@fun, x0,n]
My function F is:
function [t] = F(fun, x0, n)% Detailed explanation goes here
g=diff(fun); epsilon = 5*10^-(n+1)i=1;rng(0,'twister'); alpha = -2/vpa(subs(g,x,x0));x_current = x0;while i~=200 phi_of_x_at_x_current= x_current + (alpha*vpa(subs(fun,x,x_current))); err=abs(phi_of_x_at_x_current-x_current); if abs(1+alpha*vpa(subs(g,x,x_current)))>=1 alpha = -1*(2/vpa(subs(g,x,x0))*rand); i=1;elseif err<epsilonbreakendx_current = phi_of_x_at_x_current;i=i+1;endphi_of_x_at_x_current = phi_of_x_at_x_current - rem(phi_of_x_at_x_current,10^-n);fprintf('Answer: %f \n',phi_of_x_at_x_current);end
Best Answer