You are on page 1of 3

function [fx, ea, iter] = IterMeth(x, es, maxit)

if nargin<2||isempty(es),es=0.0001;end
if nargin<3||isempty(maxit),maxit=50;end
iter = 1; sol = 1; ea = 100;
while (1)
solold = sol;
sol = sol + x ^ iter / factorial(iter);
iter = iter + 1;
if sol~=0
ea=abs((sol - solold)/sol)*100;
end
if ea<=es || iter>=maxit,break,end
end
fx = sol;
end

>> format long


>> [approxval, ea, iter] = IterMeth(1, 1e-6, 100)
>> trueval=exp(1)

>> x=0:10;
>> y=sin(x);
>> xi=0:.25:10;
>> yi=interp1(x,y,xi);
>> plot(x,y,'o',xi,yi)

>> p=polyfit(x,y,5)

>> yi = polyval(p,xi);
>> plot(x,y,'o',xi,yi)

>> yi=spline(x,y,xi);
>> plot(x,y,'o',xi,yi)

>> p = [2 1 4 5];
>> r = roots(p)

>> poly(r)

>> r = roots([1 -6 15 -20 15 -6 1])

>> c = [3, -7, 2, 1, 1];

>> xi = 2.5;
>> yi = polyval(c, xi)

>> x = [1.1, 2.3, 3.9, 5.1];


>> y = [ 3.887, 4.276, 4.651, 2.117];
>> a = polyfit(x,y,length(x)-1)

>> Temp = [300, 400, 500, 600]';


>> Beta = 1000*[3.33, 2.50, 2.00, 1.67]';
>> Alfa = 10000*[ 0.2128, 0.3605, 0.5324, 0.7190]';
>> Ti=[321, 440, 571]';
>> Prodad = interp1(Temp, [Beta, Alfa] , Ti, 'linear');
>> [Ti, Prodad]

>> x = [ 0.0, 0.25, 0.5 0.75, 1.0]';


>> y = [0.9162, 0.8109, 0.6931, 0.5596, 0.4055]';
>> yi = [0.9, 0.7, 0.6, 0.5]';
>> xi = interp1 (y, x, yi, 'linear');
>> [yi, xi]

You might also like