Freudenstein's_equation_by_Newton Raphson's_Method

Matlab code for solving Freudenstein's equation (four-bar mechanism) using Newton Raphson's Method without 'syms'


Freudenstein's equation:
R1 cos(x)-R2 cos(y)+R3-cos(x-y)=0
R1=d/c, R2=d/a, R3=(d^2+a^2-b^2+c^2)/2ca
a=1 in; b=2 in; c=2 in; d=2 in
Calculate values of y where x varies from 0 to 360 degree at an interval of 5 degree using Newton Raphson Method. Where x=0, y=41.4
x=theta, y=phi

Source Code:
clc;
close all;
clear all;

x=(0:5*pi/180:2*pi);
y0=(41.4*pi/180);


n=input('Enter the number of decimal places:');
epsilon = 10^-(n+1);
for i=1:73
    for j=1:100
     f0=fxy(x(i),y0);
     f0_der = gxy(x(i),y0);
  yn=y0-f0/f0_der;
err=abs(yn-y0);
        if err<epsilon
        break
        end
y0 = yn;
    end
    y(i) = yn;
    fprintf('\nthera=%0.f   phi=%0.2f',(x(i)*180/pi),(y(i)*180/pi))
end

function fx = fxy(x,y)
    fx = cos(x)-2*cos(y)+5/4-cos(x-y);  %% Enter your function here.
    return;
end

function gx = gxy(x,y)
    gx = 2*sin(y)-sin(x-y);  %% Enter your function here.
    return;
end


Input Output:
Enter the number of decimal places:5

thera=0   phi=41.41
thera=5   phi=43.13
thera=10   phi=44.96
thera=15   phi=46.89
thera=20   phi=48.92
thera=25   phi=51.03
thera=30   phi=53.23
thera=35   phi=55.51
thera=40   phi=57.85
thera=45   phi=60.25
thera=50   phi=62.70
thera=55   phi=65.19
thera=60   phi=67.70
thera=65   phi=70.22
thera=70   phi=72.75
thera=75   phi=75.26
thera=80   phi=77.75
thera=85   phi=80.19
thera=90   phi=82.58
thera=95   phi=84.88
thera=100   phi=87.09
thera=105   phi=89.17
thera=110   phi=91.09
thera=115   phi=92.83
thera=120   phi=94.34
thera=125   phi=95.59
thera=130   phi=96.51
thera=135   phi=97.06
thera=140   phi=97.16
thera=145   phi=96.75
thera=150   phi=95.75
thera=155   phi=94.08
thera=160   phi=91.71
thera=165   phi=88.60
thera=170   phi=84.79
thera=175   phi=80.37
thera=180   phi=75.52
thera=185   phi=70.45
thera=190   phi=65.37
thera=195   phi=60.49
thera=200   phi=55.95
thera=205   phi=51.83
thera=210   phi=48.16
thera=215   phi=44.93
thera=220   phi=42.13
thera=225   phi=39.71
thera=230   phi=37.63
thera=235   phi=35.85
thera=240   phi=34.34
thera=245   phi=33.07
thera=250   phi=32.00
thera=255   phi=31.13
thera=260   phi=30.42
thera=265   phi=29.86
thera=270   phi=29.45
thera=275   phi=29.16
thera=280   phi=29.00
thera=285   phi=28.96
thera=290   phi=29.02
thera=295   phi=29.20
thera=300   phi=29.48
thera=305   phi=29.87
thera=310   phi=30.37
thera=315   phi=30.98
thera=320   phi=31.69
thera=325   phi=32.51
thera=330   phi=33.44
thera=335   phi=34.49
thera=340   phi=35.64
thera=345   phi=36.91
thera=350   phi=38.30
thera=355   phi=39.80
thera=360   phi=41.41>>

Comments

Post a Comment