From: irwinwck on
Hi all,
I'm new to Matlab, this is my first matlab question and i used lots of time to solve it but there are some unknown problem that i cant solve.

Question:
Write a MATLAB program, in a m-file that determines the solution of the equation 8-4.5(x-sin x)=0 by using bisection method. The solution should have approximation eorr of less than 0.001%. Create a table that display the value of X1 , Xu , f(x)f(y) and Ea for each iteration of the bisection process.

My current answer after a week of solving:
a = 2
b = 3
for x=a:b
y(a)=8-4.5*(x-sin(x))
y(b)=8-4.5*(x-sin(x))
c = (a + b)/2
for x=c
y(c)=8-4.5*(x-sin(x))
end
if y(c)==0
answer = y(c), break,
elseif y(a)*y(c)<0
a=c
end
end
------------------------------------
Your help and guidance is appreciated. Thanks
From: Jan Simon on
Dear irwinwck!

> Question:
> Write a MATLAB program, in a m-file that determines the solution of the equation 8-4.5(x-sin x)=0 by using bisection method. The solution should have approximation eorr of less than 0.001%. Create a table that display the value of X1 , Xu , f(x)f(y) and Ea for each iteration of the bisection process.
>
> My current answer after a week of solving:
> a = 2
> b = 3
> for x=a:b
> y(a)=8-4.5*(x-sin(x))
> y(b)=8-4.5*(x-sin(x))
> c = (a + b)/2
> for x=c
> y(c)=8-4.5*(x-sin(x))
> end
> if y(c)==0
> answer = y(c), break,
> elseif y(a)*y(c)<0
> a=c
> end
> end

This is a nice point to start from.
At first, you might learn something about the FOR loops. Start with a simple loop:
for i = 1:10
disp(i);
end
Then read the "Getting started" from Matlab's help pages. Afterwards, I think, you will modify "y(a)=8-4.5*(x-sin(x))" to e.g. "ya = 8-4.5*(x-sin(x))", because it is not meaningful to use the variable [a] as index for the [y].

Good luck and welcome to Matlab, Jan
From: ImageAnalyst on
And of course he's only changing y(2) and y(3) and they are both the
same value/formula. Plus c = 5/3 which will throw an error when you
try to get the 2.5th element of y. And then there's the issue of what
the heck if y(c)? Why should it be 0? Plus there's no increment in
the for loop so it goes from 2 to 3 in just one single step. This
code is so messed up I don't know where to start. There's no way I
believe that a week of effort produced this. Other than just learning
MATLAB (or computer programming) in general, maybe Googling for code
is a good way to find some code or pseudocode that you can use as an
example for writing your own MATLAB code. Here's 29,200 hits for
"bisection method MATLAB":
http://www.google.com/search?hl=en&source=hp&q=bisection+method+matlab&aq=1&oq=bisection&aqi=g10
 | 
Pages: 1
Prev: convert 3D matrix into 2D
Next: adaptive threshold