Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

correct the following MATLAB code and comment in each step ? clear all; a=0, b=1, tol=0.001, nmax =50, nstudents = 2; for k =1:nstudents %ID

correct the following MATLAB code and comment in each step ?

clear all; a=0, b=1, tol=0.001, nmax =50, nstudents = 2; for k =1:nstudents %ID digits in reverse order if k==1 a5=1; a4=8; a3=4; a2=1; a1=0; a0=2; end if k==2 a5=1; a4=4; a3=0; a2=1; a1=0; a0=0; end x_sol = zeros(nmax); ETF_err = zeros(nmax); %plotting x=-1:0.1:1; n=size(x,2); z=zeros(n); for i=1:n z(i)=F(x(i),a5,a4,a3,a2,a1,a0); end figure; plot(x,z) if k==1 a=-0.5, b=1; end if k==2 a=-0.5, b=1.5; end test = F(a,a5,a4,a3,a1,a0)*F(b,a5,a4,a3,a2,a1,a0); if test > 0 disp ('wrong interval, please neter a valid interval') else %Start my bisection for i=1:nmax x_sol(i) = (a+b)/2; ETF_err(i)= abs(F(x_sol(i),a5,a4,a3,a2,a1,a0)); if ETF_err(i)< tol end test = F(a,a5,a4,a3,a2,a1,a0)*F(x_sol(i),a5,a4,a3,a2,a1,a0); if test <0 b=b; else a=x_sol(i); end end last_ind = i; last_sol = x_sol(i); Last_err = ETF_err(i); save -append myBisecResult last_ind last_sol Last_err figure; hold on; plot(x_sol(1:i),'b', 'linewidth', 2); plot(ETF_err(1:i), 'r', 'linewidth', 2); h = legend ("Bisection solution curve", "Bisection Error curve"); legend (h, "location", "northeast"); title ("Solution and error curves for Bisection Method"); end end %close sfor k

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions