
(1) Bisection Method in MATLAB :
a=input('Enter function with right hand side zero:','s');
f=inline(a);
xl=input('Enter the first value of guess interval:') ;
xu=input('Enter the end value of guess interval:');
tol=input('Enter the allowed error:');
if f(xu)*f(xl)<0
else
fprintf('The guess is incorrect! Enter new guesses\n');
xl=input('Enter the first value of guess interval:\n') ;
xu=input('Enter the end value of guess interval:\n');
end
for i=2:1000
xr=(xu+xl)/2;
if f(xu)*f(xr)<0
xl=xr;
else
xu=xr;
end
if f(xl)*f(xr)<0
xu=xr;
else
xl=xr;
end
xnew(1)=0;
xnew(i)=xr;
if abs((xnew(i)-xnew(i-1))/xnew(i))<tol,break,end
end
str = ['The required root of the equation is: ', num2str(xr), '']
(2) RK4 Method in MATLAB :
function a = runge_kutta(df)
% asking initial conditions
x0 = input('Enter initial value of x : ');
y0 = input ('Enter initial value of y : ');
x1 = input( 'Enter value of x at which y is to be calculated : ');
tol = input( 'Enter desired level of accuracy in the final result : ');
%choose the order of Runge-Kutta method
r = menu ( ' Which order of Runge Kutta u want to use', ...
' 2nd order ' , ' 3rd order ' , ' 4th order ');
switch r
case 1
% calculating the value of h
n =ceil( (x1-x0)/sqrt(tol));
h = ( x1 - x0)/n;
for i = 1 : n
X(1,1) = x0; Y (1,1) = y0;
k1 = h*feval( df , X(1,i), Y(1,i));
k2 = h*feval( df , X(1,i) + h , Y(1,i) + k1);
k = 1/2* ( k1+ k2);
X( 1, i+1) = X(1,i) + h;
Y( 1 ,i+1) = Y(1,i) + k;
end
case 2
% calculating the value of h
n =ceil( (x1-x0)/nthroot(tol,3));
h = ( x1 - x0)/n;
for i = 1 : n
X(1,1) = x0; Y (1,1) = y0;
k1 = h*feval( df , X(1,i), Y(1,i));
k2 = h*feval( df , X(1,i) + h/2, Y(1,i) + k1);
k3 = h*feval( df , X(1,i) + h, Y(1,i) + k2);
k = 1/6* ( k1+ 4*k2 + k3);
X( 1, i+1) = X(1,i) + h;
Y( 1 ,i+1) = Y(1,i) + k;
end
case 3
% calculating the value of h
n =ceil( (x1-x0)/nthroot(tol,3));
h = ( x1 - x0)/n;
for i = 1 : n
X(1,1) = x0; Y (1,1) = y0;
k1 = h*feval( df , X(1,i), Y(1,i));
k2 = h*feval( df , X(1,i) + h/2, Y(1,i) + k1);
k3 = h*feval( df , X(1,i) + h/2, Y(1,i) + k2);
k4 = h*feval( df , X(1,i) + h, Y(1,i) + k3);
k = 1/6* ( k1+ 2*k2 + 2*k3 + k4);
X( 1, i+1) = X(1,i) + h;
Y( 1 ,i+1) = Y(1,i) + k;
end
end
%displaying results
fprintf( 'for x = %g \n y = %g \n' , x1,Y(1,n+1))
%displaying graph
x = 1:n+1;
y = Y(1,n+1)*ones(1,n+1) - Y(1,:);
plot(x,y,'r')
xlabel = (' no of interval ');
ylabel = ( ' Error ');
Use bisection and RK4 write matlab code in Fnd v such that ycoo) in Fnd v such that ycoo)
Write a User Defined Function in Matlab solve for the roots of a function using bisection method. The user provides two variables for the function to test and bisect if needed.
3. Use the bisection MATLAB program to estimate the roots of the function k(x) = x2 - 4, where x's range is [-1, 3). Include solutions for this method in the report. 4. Write a MATLAB program that uses the false-position method to estimate the roots of the function k(x) in problem#3. Include your m-file and solutions for this method in the report. In addition, submit your m-file separately.
Use Matlab
2. Write a matlab code for fixed point iteration to find appr Use this method to solve ar323: Hint: f() (3023)l
2. Write a matlab code for fixed point iteration to find appr Use this method to solve ar323: Hint: f() (3023)l
Hi, I need help doing this. 3. Use the bisection MATLAB program to estimate the roots of the function k(x) = x2 - 4, where x’s range is [-1, 3]. Include solutions for this method in the report. Write a MATLAB program that uses the false-position method to estimate the roots of the function k(x) in problem#3. Include your m-file and solutions for this method in the report. In addition, submit your m-file separately.
Part a: Write a Matlab code that generate Exponential Function. Part b Write a Matlab code that generate sinusoidal Function. Part c Write a Matlab code that generate Unit Ramp delay (shift) function
Write code to approximate √25 3 by applying the a) bisection method and b) false position method to the equation ?^3 = 25. Code the algorithms. Choose the starting guesses. Determine the result accurate to at least to 5 sig figs.
MATLAB Code:
?MATLAB Code:
Write a function that converts a given letter grade it will print its equivalence in numerical scale. For example if the user enters A, then your function should print a message stating that the grade must be between 90 and 100. B is between 80 and 89, etc. Everything under 60 is F. Use the switch-case function. Use fprintf to display the results on the screen.
please use **matlab**. do not calculate by your hands.
just write matlab code for solving the problem.I wite the formula
of the GMR. and I drow the strands conductor. And also I write the
given value of r' that denote the D11=...=D99. please solve with
matlab.
ure oe laus Atl s trands bawe the sam D tem Please use Matbab eor usihs the proklem
ure oe laus Atl s trands bawe the sam D tem Please use Matbab eor usihs...
Use matlab
Need the matlab code
Problem 3: (a) Use Fourier transform to find i(t) in the circuit below if v.( 10e2tu(t). Use MATLAB to solve your problem. (b) Plot the magnitude and phase spectrum of the current I(o). 2Ω 3 20 1 H Submit the solution in word file. The used MATLAB code should be included Due date: last day of classes
Please use matlab, post the code, and dont just write
the code by hand. Thank you!
4 [3 points] Use the function f(x on the interval [5, 5] and the 11 points below to find a N-10 Lagrange polynomial, using MATLAB. You will need to write code for and plot the polynomial as a function of x, but you do not have to write the polynomials down by hand 5 0 2 3 4 5 f(x) | 0.0399 | 00623...