Roots of Polynomials by loop in matlab

In summary, the speaker is trying to find the roots of polynomials with variable coefficients using a specific command. They are having trouble with the syntax and are advised to use the .^ operator instead of the ^ operator. They are also reminded to consider the power of x associated with each coefficient to avoid getting a straight line when calculating the velocities. Alternatively, they can calculate the roots symbolically to get expressions for the roots in terms of the coefficients.
  • #1
adnan jahan
96
0
Dear Friends! I need to find roots of polynomials with variable coefficients, The command I used is

w=0:50
A=w^2
B=w^3+2
C=w+2*w^2
D=w
E=w./2
ss=[A B C D E]
xi=roots(ss)
by this I find all the roots of equation,
I want to find velocities by setting
v1=w/xi(1)
v2=w/xi(2)
v3=w/xi(3)
v4=w/xi(4)
v5=w/xi(5)
and plot (w,v1)
the plot is straight line which is because the velocities i found is not the same as I need because of command xi(1). . . . I need list of values for v1, . . .

Can anyone please guide me in syntax error I used...
 
Physics news on Phys.org
  • #2
You need to use .^ to raise each element of w to the correct power. The ^ operator does matrix power if the operand is anything but a scalar (w is a vector).

Also, given that xi(n) is just a scalar root, what are you actually trying to calculate with v1,...,v5? Do you need to add in the power of x that is associated with each coefficient? Otherwise you'll always get a straight line since you're just dividing the numbers 1 through 50 (in vector w) by the scalar root (in xi(n)).

As an alternative, you can calculate these roots symbolically to get some expressions for the roots in terms of the coefficients.
 

Related to Roots of Polynomials by loop in matlab

1. What is the purpose of finding roots of polynomials using a loop in Matlab?

The purpose of finding roots of polynomials using a loop in Matlab is to determine the values of the independent variable (usually denoted as x) that make the polynomial equation equal to zero. These values are called the roots or solutions of the polynomial and are important in various mathematical and scientific applications.

2. How does the loop in Matlab help to find roots of polynomials?

The loop in Matlab allows for repeated calculations of the polynomial equation with different values of the independent variable. By checking if the equation equals zero for each value of x, the loop can identify the values that are roots of the polynomial.

3. Can the loop in Matlab find all the roots of a polynomial?

Yes, the loop in Matlab can find all the roots of a polynomial, as long as the loop is set up to cover the entire range of possible values for the independent variable. However, in some cases, the loop may not be able to find all the roots due to limitations in the precision of calculations.

4. What are the benefits of using a loop in Matlab to find roots of polynomials?

Using a loop in Matlab to find roots of polynomials allows for a more efficient and automated process compared to manually solving the equation. It also allows for a larger number of calculations to be performed, which can be useful when dealing with complex polynomials or a large number of data points.

5. Are there any limitations to using a loop in Matlab for finding roots of polynomials?

One potential limitation of using a loop in Matlab to find roots of polynomials is that it may not be able to handle certain types of polynomials, such as those with extremely large or small coefficients. In addition, the precision of the calculations may also affect the accuracy of the roots found by the loop.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
Replies
5
Views
542
Replies
2
Views
934
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Introductory Physics Homework Help
Replies
3
Views
797
  • Advanced Physics Homework Help
Replies
4
Views
1K
Replies
1
Views
785
  • Beyond the Standard Models
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
Back
Top