Can someone help me out please even my profosser don't help me so im asking anyone to help me out on matlab. i don't even know where to start and how to form the formula.

The first MATLAB function that you will need to create is:

function [count] = RootCount(y)

This function should determine the number of roots in the equation represented by the input argument vector y and return this value via the output argument count.

The easiest way to accomplish this task is to examine each adjacent pair of y values (y(1) and y(2), y(2) and y(3), etc.) and count how many times there is a sign change between the two values. This change of sign indicates that there is a root (zero point), as the equation has crossed the x axis. Hint: If the product of the two adjacent values is negative, then there is a root (zero point), as the equation has crossed the x axis.

Create a MATLAB script file to test your function and find the number of roots in the following equations, over the specified intervals:

y(t) = -0.1t4 + 0.8t3 + 10t - 70 in the interval 0 ≤ t ≤ 8

y(x) = exsin(x) – 5
in the interval 0 ≤ x ≤ 20

In both cases the increment for either t or x should be quite small, probably of the order 0.01.

If your function is working correctly, you should get values of 1 and 7, respectively.

Finding Roots

Next we want to create second MATLAB function:

function [count, values] = RootValues(x, y)

This function, in addition to find the number of roots in the equation, will also return a vector containing the root values.

To accomplish this task, when you find a root value, take the average of the corresponding x values to find the approximate value of the root. NOTE: The x vector which is sent to the function as an input argument should contain the values used to evaluate the equation and generate the y vector.

Once again create a MATLAB scrip file to test this function and once again use the following equations over the specified intervals:

y(t) = -0.1t4 + 0.8t3 + 10t - 70in the interval 0 ≤ t ≤ 8

y(x) = exsin(x) – 5
in the interval 0 ≤ x ≤ 20

RootCount Revisited

Lets revisit our RootCount function, only this time lets use it to determine the number of roots in a selection of sine functions in the interval 0 ≤ x ≤ 2*pi.

Create a MATLAB script file to fine the number of roots for the following sine functions:

sin(x) sin(2*x) sin(3*x) sin(10*x)

Did you get the values 1, 3, 5, and 19, respectively? You should have!

In the interval 0 ≤ x ≤ 2*pi, we know that sin(x) makes one oscillation, sin(2*x) makes 2 oscillations, sin(3*x) makes 3 oscillations, and sin(10*x) makes 10 oscillations. Can we find a relationship between the number of oscillations (frequency) and the number of roots? Kind of looks like (number of roots + 1) / 2 does it?

2. Originally Posted by gndoj
Can someone help me out please even my profosser don't help me so im asking anyone to help me out on matlab. i don't even know where to start and how to form the formula.

The first MATLAB function that you will need to create is:

function [count] = RootCount(y)

This function should determine the number of roots in the equation represented by the input argument vector y and return this value via the output argument count.

The easiest way to accomplish this task is to examine each adjacent pair of y values (y(1) and y(2), y(2) and y(3), etc.) and count how many times there is a sign change between the two values. This change of sign indicates that there is a root (zero point), as the equation has crossed the x axis. Hint: If the product of the two adjacent values is negative, then there is a root (zero point), as the equation has crossed the x axis.

Create a MATLAB script file to test your function and find the number of roots in the following equations, over the specified intervals:

y(t) = -0.1t4 + 0.8t3 + 10t - 70 in the interval 0 ≤ t ≤ 8

y(x) = exsin(x) – 5 in the interval 0 ≤ x ≤ 20

In both cases the increment for either t or x should be quite small, probably of the order 0.01.

If your function is working correctly, you should get values of 1 and 7, respectively.

Finding Roots

Next we want to create second MATLAB function:

function [count, values] = RootValues(x, y)

This function, in addition to find the number of roots in the equation, will also return a vector containing the root values.

To accomplish this task, when you find a root value, take the average of the corresponding x values to find the approximate value of the root. NOTE: The x vector which is sent to the function as an input argument should contain the values used to evaluate the equation and generate the y vector.

Once again create a MATLAB scrip file to test this function and once again use the following equations over the specified intervals:

y(t) = -0.1t4 + 0.8t3 + 10t - 70in the interval 0 ≤ t ≤ 8

y(x) = exsin(x) – 5 in the interval 0 ≤ x ≤ 20

RootCount Revisited

Lets revisit our RootCount function, only this time lets use it to determine the number of roots in a selection of sine functions in the interval 0 ≤ x ≤ 2*pi.

Create a MATLAB script file to fine the number of roots for the following sine functions:

sin(x) sin(2*x) sin(3*x) sin(10*x)

Did you get the values 1, 3, 5, and 19, respectively? You should have!

In the interval 0 ≤ x ≤ 2*pi, we know that sin(x) makes one oscillation, sin(2*x) makes 2 oscillations, sin(3*x) makes 3 oscillations, and sin(10*x) makes 10 oscillations. Can we find a relationship between the number of oscillations (frequency) and the number of roots? Kind of looks like (number of roots + 1) / 2 does it?
You have posted your assignment/s, but without some information about what it is you are having problems with there is not much we can do other than post solutions, and we don't like doing that.

Also, without some idea of what your course is and its aims in using Matlab a solution from an old hand may well be of no use to you.

(also there is a whole class of roots that the suggested method will miss, as its a method of finding where the function changes sign and so will miss all roots of even multiplicity, and any where a trial point is an exact zero)

CB

3. i know that i post the whole problem, but i don't know where to start and i thought that if i post the whole problem online maybe someone can help. i mean i can't even find it in the book, i even ask the professor about the problem and his not helping much not just me, but the whole class room. If u have any ideas where to start i really appreciate yuor help. thank you

4. Originally Posted by gndoj
i know that i post the whole problem, but i don't know where to start and i thought that if i post the whole problem online maybe someone can help. i mean i can't even find it in the book, i even ask the professor about the problem and his not helping much not just me, but the whole class room. If u have any ideas where to start i really appreciate yuor help. thank you
You need to write a function that accepts a function handle as argument and steps through the range you are investigating with the given step size recording every time the function passed as the function handle changes sign.

You need to look up in the help system "function handle" if you do not know what one is, and "for" and "if" control structures.

When you have made an attempt at something based report back here what you have done.

CB

5. %Counting Roots
%Finding numbers of roots
t=0:0.01:8;
Yt=-0.1*t.^4+0.8*t.^3+10*t-70;
Ynew=Yt<0;
a=diff(Ynew);
a=find(a);
a=size(a);
a=a(2);
disp(a);
%One Root
%Part 1b
x=0:0.01:20;
Yx=exp(x).*sin(x)-5;
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%Seven Roots

%Find the root values
t=0:0.01:8;
Yt=-0.1*t.^4+0.8*t.^3+10*t-70;
Ynew=Yt<0;
a=diff(Ynew);
a=find(a);
a=a.*0.01;
disp(a);
%One Root
%Part 1b
x=0:0.01:20;
Yx=exp(x).*sin(x)-5;
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=a.* 0.01;
disp(a);
%Seven Roots

%sin(x) on interval 0<x<2*pi
x=0:0.01:2*pi;
Yx=sin(x);
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%1 root

%sin(2*x) on interval 0<x<2*pi
x=0:0.01:2*pi;
Yx=sin(2*x);
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%3 roots

%sin(3*x) on interval 0<x<2*pi
x=0:0.01:2*pi;
Yx=sin(3*x);
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%5 roots

%sin(10*x) on interval 0<x<2*pi
x=0:0.01:2*pi;
Yx=sin(10*x);
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%19 roots

this is what i did. What do you think iam on the right track?

6. Originally Posted by gndoj
%Counting Roots
%Finding numbers of roots
t=0:0.01:8;
Yt=-0.1*t.^4+0.8*t.^3+10*t-70;
Ynew=Yt<0;
a=diff(Ynew);
a=find(a);
a=size(a);
a=a(2);
disp(a);
%One Root
%Part 1b
x=0:0.01:20;
Yx=exp(x).*sin(x)-5;
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%Seven Roots

%Find the root values
t=0:0.01:8;
Yt=-0.1*t.^4+0.8*t.^3+10*t-70;
Ynew=Yt<0;
a=diff(Ynew);
a=find(a);
a=a.*0.01;
disp(a);
%One Root
%Part 1b
x=0:0.01:20;
Yx=exp(x).*sin(x)-5;
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=a.* 0.01;
disp(a);
%Seven Roots

%sin(x) on interval 0<x<2*pi
x=0:0.01:2*pi;
Yx=sin(x);
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%1 root

%sin(2*x) on interval 0<x<2*pi
x=0:0.01:2*pi;
Yx=sin(2*x);
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%3 roots

%sin(3*x) on interval 0<x<2*pi
x=0:0.01:2*pi;
Yx=sin(3*x);
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%5 roots

%sin(10*x) on interval 0<x<2*pi
x=0:0.01:2*pi;
Yx=sin(10*x);
Ynew=Yx<0;
a=diff(Ynew);
a=find(a);
a=length(a);
disp(a);
%19 roots

this is what i did. What do you think iam on the right track?

That seems to be substantialy OK, can't run all of it here but what I can looks OK, now you have to produce a function to do this, and pass the expression to it as an argument.

CB

7. I don't really get your question can you please explain a little bit more i don't what you mean produce a function?

8. Originally Posted by gndoj
I don't really get your question can you please explain a little bit more i don't what you mean produce a function?
Somewhere define the function you want to count roots of, either as in a .m file or at the console as an anonymous function:

Code:
  Yt=@(x)  -0.1*t.^4+0.8*t.^3+10*t-70;
Then create the .m file CountingRoots.m containing the following code:

Code:
function count=CountingRoots(ff)
%Counting Roots
%Finding numbers of roots

t=0:0.01:8;
Ynew=(ff(t)<0);
a=diff(Ynew);
a=find(a);
a=size(a);
a=a(2);
disp(a);
count=a;
To call this type the following in the console window:

Code:
a=CountingRoots(Yt)

9. now i get it thank you for your help