Question

Please do this in Matlab.

Problem8: (ME3400: Engineering Dynamics; ME5800: Combustion Engines) Root-finding techniques to solve engineering problems Consider the slider crank mechanism (commonly found in an engine crank shaft and piston assembly for most reciprocating engines). The combustion of gas generates the backward-and-forward motions of the slider, known as reciprocating mot converted into linear motions through the slider crank mechanism TOC ions. Th e reciprocating motions are Consider a simplified kinematics problem as shown in the figure below The position of the point P is denoted by s(t). From geometry, we have Rod where, α is the angle between the bar on the right and the horizontal. For this problem, we have0.2 m and 2 0.4 m Crank radius 400 mm 200 mm 0 The two angles are related by the law of sines sin9 sin a Differentiating equation (1) with respect to time gives the velocity of the point P ds dt15 dt From equation (2), the angular velocities are related by de dt de dt Suppose _-1 rad/s , determine the angle θ when the velocity of P, v.--0.2 m/s . Choose a suitable numerical method to obtain the answer and compare with the answer obtained from using fzero

Not sure if you need this code:

e cofunction [x, er, n] = FixedPoint(g, x1, maxtol, maxitr)

if nargin < 4, maxitr = 25; end
if nargin < 3, maxtol = 1e-3; end
k = 0 ;   
er = 1;
x = x1;   

while er >= maxtol && k < maxitr
k=k+1;
xold = x;
x=g(x);
er=abs((x-xold)/x);

fprintf('iter = %i, x = %e, er = %e ', k,x,er);
end

n=k;

if n == maxitr && er >= maxtol
fprintf(' ')
warning('Maximum number of iterations reached before convergence')
fprintf(' Solution not obtained in %d iterations. ',maxitr);
end

end

function [x,er,N]=Newtonroot(fun,funder,x1,maxtol,maxitr)
if nargin < 4, maxitr = 25; end
if nargin < 3, maxtol = 1e-3; end
k = 0 ;
er = 1;
x = x1;
g = funder;
while er >= maxtol && k < maxitr
k=k+1;
xold=x;
x=x-fun(x)/g(x);
er=abs((x-xold)/x);
fprintf('iter = %i, x = %e, er = %e ', k,x,er);

end
N=k;

if N == maxitr && er >= maxtol
fprintf(' ')
warning('Maximum number of iterations reached before convergence')
fprintf(' Solution not obtained in %d iterations. ',maxitr);
end
end

function df = derivative(f)

sym_f = sym(f);
df = matlabFunction(simplify(diff(sym_f))); % simplify command is optional
end

0 0
Add a comment Improve this question Transcribed image text
Answer #1


θ+2.cesa D -4 Άλθ 요 2- dt cl S dt- «A .co器. AA:8蠻.奈 im器 2 dE%Matlab code for finding the ta value using fzero and Bisection method clear all close all %Finding root using fzero The parameterized function. 11-0.2; 12-0.4; dth-l vp-0.2; myfun (theta) vp +(11sin (theta) dth)+((112*sin theta)*cos (theta)) (sqrt(12 2- 11*2*(sin (theta))2))) dth); %Finding theta value for using fzero xx- fzero( (x) myfun (),0.001) theta_fz-rad2deg (xx); fprint f ( The root using fzero is the ta=%f ,the tafz) Finding theta value using Regula Falsi method %initialization of theta value ; a and b a-deg2rad ( 90); b-0; fprint f ( - For initial guess of theta=%d and the ta=%d. In, rad2deg(a),b) %initialization of loop err-l c=0; xx-(atb)/2; %loop for Regula falsi iterations while err>10-12 xx (c)=(a+b )/ 2; mm=double (myfun ( xx ( c ) ) ) ; if mm>=0 a-xx(c) else b-xx (c) err-abs (myfun(xx(c))) fprintf( The root using bisection method is theta-f n,rad2deg (xx (end))) 용号号응용号号응용号号응용号号응용号号% End Of Code 융융용용융융용용융융용용융융용용융융용용융융 The root using fzero is theta-47.05859 7 For initial guess of theta-90 and theta 0. The root using bisection method is theta 47.058597 Published with MATLABE R2018a

%Matlab code for finding theta value using fzero and Bisection method
clear all
close all
%Finding root using fzero
% The parameterized function.
l1=0.2; l2=0.4; dth=1; vp=-0.2;
myfun = @(theta) vp+(l1*sin(theta)*dth)+(((l1^2*sin(theta)*cos(theta))/(sqrt(l2^2-l1^2*(sin(theta))^2)))*dth);

%Finding theta value for using fzero
xx= fzero(@(x) myfun(x),0.001);
theta_fz=rad2deg(xx);
fprintf('The root using fzero is theta=%f ',theta_fz)
%Finding theta value using Regula Falsi method

%initialization of theta value; a and b
a=deg2rad(90);
b=0;
fprintf(' For initial guess of theta=%d and theta=%d. ',rad2deg(a),b)
%initialization of loop
err=1;
c=0;
xx=(a+b)/2;

%loop for Regula falsi iterations
while err>10^-12
    c=c+1;
    xx(c)=(a+b)/2;
    mm=double(myfun(xx(c)));
    if mm>=0
        a=xx(c);
    else
        b=xx(c);
    end
    err=abs(myfun(xx(c)));
end

fprintf('The root using bisection method is theta=%f ',rad2deg(xx(end)))

%%%%%%%%%%%%%%%%%%%% End Of Code %%%%%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Please do this in Matlab. Not sure if you need this code: e cofunction [x, er,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me fix this halleyroot funtion , in matlab function [x, er, n] = Halleyroot(fun,x1,maxtol,maxitr)...

    Please help me fix this halleyroot funtion , in matlab function [x, er, n] = Halleyroot(fun,x1,maxtol,maxitr) if (nargin < 5), maxitr = 25; end if (nargin < 4), maxtol = 1e-4; end k = 0; er = 1; x = x1; funder= derivative(fun); while er >= maxtol && k < maxitr k = k+1; % increment the iteration number xold = x; x = xold-fun(xold)/funder(xold); er = abs((x-xold)/x); fprintf('iter = %i\t x = %f\t f(x) = %f\t er = %f...

  • I'm working on the newton's method on matlab, could someone help me and show what two...

    I'm working on the newton's method on matlab, could someone help me and show what two lines are needed to be added in the codes in order to make this function work? function sample_newton(f, xc, tol, max_iter) % sample_newton(f, xc, tol, max_iter) % finds a root of the given function f over the interval [a, b] using Newton-Raphson method % IN: % f - the target function to find a root of % function handle with two outputs, f(x), f'(x)...

  • can some one edit this code p(1)=0.4 p(2)=0.5 e=0.00001 *secant metod >> syms x; f=(1/x) -2;...

    can some one edit this code p(1)=0.4 p(2)=0.5 e=0.00001 *secant metod >> syms x; f=(1/x) -2; e=input('Enter the epsilon: \n'); p(1)=input('Enter xo(1st guess) : '); p(2)=input('Enter x1(2nd guess): '); i=3; Error(i)=1; while Error(i)>=e p(i)=P(i-1)-(f(p(i-1))*(p(i-1)-p(1-2))/(f(p(i-1))-f(p(i- 2)))); Error(i)=abs(p(i-1)-p(i-2)); i=i+1; end fprintf('The Root is : %f \n', root); fprintf('No. of Iterations : %d\n',i); Enter the epsilon: 0.00001 Enter x (1st guess): 0.4 Enter x1(2nd guess): 0.5 Array indices must be positive integers or logical values. Error in sym/subsref (line 900) R_tilde = builtin('subsref',...

  • in matlab -Consider the equation f(x) = x-2-sin x = 0 on the interval x E [0.1,4 π] Use a plot to approximately locate the roots of f. To which roots do the fol- owing initial guesses converge wh...

    in matlab -Consider the equation f(x) = x-2-sin x = 0 on the interval x E [0.1,4 π] Use a plot to approximately locate the roots of f. To which roots do the fol- owing initial guesses converge when using Function 4.3.1? Is the root obtained the one that is closest to that guess? )xo = 1.5, (b) x0 = 2, (c) x.-3.2, (d) xo = 4, (e) xo = 5, (f) xo = 27. Function 4.3.1 (newton) Newton's method...

  • MATLAB help! I have some MATLAB Assignment to do, the proffesor requires all the small parts...

    MATLAB help! I have some MATLAB Assignment to do, the proffesor requires all the small parts in order to get full credit. Help me out, thank you f LAB SECTION NAME HW6P3 (30 points) following are infinite series representations of the function, un pra i a script file HW6P3 that determines the value of the function from the sum of the series for a given value of x. The program (1 pt) must prompt the user to enter a value...

  • Can you help me with this question please? For the code, please do it on MATLAB. Thanks

    Can you help me with this question please? For the code, please do it on MATLAB. Thanks 7. Bonus [3+3+4pts] Before answering this question, read the Google page rank article on Pi- azza in the 'General Resources' section. The Google page rank algorithm has a lot to do with the eigenvector corresponding to the largest eigenvalue of a so-called stochastic matrix, which describes the links between websites.2 Stochastic matrices have non-negative entries and each column sums to1, and one can...

  • Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you...

    Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you 5. In this problem we will investigate using the Secant Method to approximate a root of a function f(r). The Secant Method is an iterative approach that begins with initial guesses , and r2. Then, for n > 3, the Secant Method generates approximations of a root of f(z) as In-1-In-2 n=En-1-f (x,-1) f(Fn-1)-f(-2) any iteration, the absolute error in the approximation can be...

  • the code in the photo for this I.V.P dy/dx= x+y. y(0)=1 i need the two in the photo thank you New folder Bookmark...

    the code in the photo for this I.V.P dy/dx= x+y. y(0)=1 i need the two in the photo thank you New folder Bookmarks G Google dy/dx x+y, y(0)=1 2 h Exact Solution 1.8 Approximate Solution Mesh Points 1.6 -Direction Fied 1.4 1.2 1 0.8 04 0.2 0.3 0.1 0 X CAUsersleskandara\Desktop\New folder emo.m EDITOR PUBLISH VEW Run Section FILE NAVIGATE EDIT Breakpoints Run Run and FL Advance Run and Advance Time BREAKPOINTS RUN 1 - clear all 2 clc 3-...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT