Subhan331

Mr. SUBHAN ULLAH

15 Reputation

0 Badges

0 years, 175 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by Subhan331

@vv thanks alot and how to plot this result

@Carl Love i need same code for transcendental function

@Samir Khan can you please do it for x^2-2 with a=1 and b=3
 

bisection := proc (a, b, Tinit) local epsilonABS, epsilonSTEP, c, atemp, btemp; epsilonABS := .1; epsilonSTEP := .1; atemp := a; btemp := b; while epsilonSTEP <= btemp-atemp or epsilonABS <= abs(HeatBalance_code(atemp, Tinit)) and epsilonABS <= abs(HeatBalance_code(btemp, Tinit)) do c := (1/2)*atemp+(1/2)*btemp; if abs(HeatBalance_code(c, Tinit)) <= 0 then break elif HeatBalance_code(atemp, Tinit)*HeatBalance_code(c, Tinit) < 0 then btemp := c else atemp := c end if end do; return atemp end proc:

``


 

Download no_result.mw
 

bisection := proc (a, b, Tinit) local epsilonABS, epsilonSTEP, c, atemp, btemp; epsilonABS := .1; epsilonSTEP := .1; atemp := a; btemp := b; while epsilonSTEP <= btemp-atemp or epsilonABS <= abs(HeatBalance_code(atemp, Tinit)) and epsilonABS <= abs(HeatBalance_code(btemp, Tinit)) do c := (1/2)*atemp+(1/2)*btemp; if abs(HeatBalance_code(c, Tinit)) <= 0 then break elif HeatBalance_code(atemp, Tinit)*HeatBalance_code(c, Tinit) < 0 then btemp := c else atemp := c end if end do; return atemp end proc:

``


 

Download no_result.mw

 

@Carl Love how  to write a code for non linear function like exp(x)-sin(x)+2 

@tomleslie what if i want to have for a non-linear function like exp(x)-sin(x)+2

@Kitonum but we did not mention k=6 

 

@Kitonum why its shows only 6 iterations for n=10 or hw can we find more?

@Kitonum thanks 


I need a general coding in which we can change function and number of iteration at any time 

``

tol := 0.1e-5; n := 10; x := Array(0 .. n); x[0] := .1; f := proc (x) options operator, arrow; x^2-3 end proc; h := proc (x) options operator, arrow; unapply(diff(f(x), x), x) end proc; for k to n do x[k] := evalf(x[k-1]-f(x[k-1])/h(x[k-1])); if abs(x[k]-x[k-1]) < tol then print("Number of iterations" = k); print("approximate solution" = x[k]); print(f(x[k])); break end if; x[k-1] := x[k] end do; interface(rtablesize = n+1); x(); interface(rtablesize = n); plot([f(p), f(x[k-1])+(p-x[k-1])*h(x[k-1])], p = -1 .. 3, colour = [red, black])

0.1e-5

 

10

 

.1

 

proc (x) options operator, arrow; x^2-3 end proc

 

proc (x) options operator, arrow; unapply(diff(f(x), x), x) end proc

 

Error, (in h) invalid input: diff received .1, which is not valid for its 2nd argument

 

10

 

Array(0 .. 10, {0 = .1}, datatype = anything, storage = rectangular, order = Fortran_order)

 

11

 

Error, (in h) invalid input: diff received .1, which is not valid for its 2nd argument

 

``

``


 

Download err0r.mw

@tomleslie 

@tomleslie why dont it shows values for each iteration?

@tomleslie Thanks alot God Bless You

Page 1 of 1