Can I Find 21 Equidistant Roots Between [-1,1] of a Function in Matlab?

  • Context: MATLAB 
  • Thread starter Thread starter kappa
  • Start date Start date
  • Tags Tags
    Function Roots
Click For Summary

Discussion Overview

The discussion revolves around finding 21 equidistant values of a function defined as f(x) = (1 − 6x^2)^-1 within the interval [-1,1]. Participants explore methods to compute these values using MATLAB, particularly focusing on the use of functions like fsolve and linspace.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant initially inquires about finding roots of the function but later clarifies the need for evaluating the function at 21 equidistant points.
  • Another participant points out that the function does not have roots in the traditional sense, suggesting the user may mean points where the function is undefined.
  • Several participants propose using MATLAB's linspace function to generate equidistant x values and evaluate the function at these points.
  • There are discussions about the correct syntax for defining the function and using the subs function in MATLAB.
  • A participant shares their attempt to implement the function using an inline function and a loop to compute y values for the generated x values.

Areas of Agreement / Disagreement

Participants generally agree on the approach of using equidistant values and MATLAB functions, but there is some confusion regarding the definition of roots and the correct implementation syntax.

Contextual Notes

There are unresolved issues regarding the correct use of the subs function and the handling of the function's undefined points. The discussion does not clarify all assumptions about the function's behavior across the specified interval.

Who May Find This Useful

Individuals interested in MATLAB programming, particularly in evaluating functions over specified intervals, may find this discussion relevant.

kappa
Messages
7
Reaction score
0
i have this function f(x) = (1 − 6x^2)^-1
and I need 21 roots between [-1,1] equidistant (the points to be at same distance from one to another)

can i find the roots with some function in matlab? i found out just the polyval function for polynom
 
Physics news on Phys.org
If you define the root to be the value of x such that f(x) = 0, there are no roots (do you see why?). Do you instead mean the values of x such that f(x) is undefined?
 
gb7nash said:
If you define the root to be the value of x such that f(x) = 0, there are no roots (do you see why?). Do you instead mean the values of x such that f(x) is undefined?

yes i was rong i need the value of f(x)=... when x is from [-1,1] (for 21 values) I do it with fsolve?
 
kappa said:
yes i was rong i need the value of f(x)=... when x is from [-1,1] (for 21 values) I do it with fsolve?

Do you just want to plug in 21 equidistant values of x between [-1,1] and find what f(x) is for each value? If so, you could use:


x_values = linspace(-1,1,21)
y_values = subs(y,x) 'y is the function in terms of x
 
gb7nash said:
Do you just want to plug in 21 equidistant values of x between [-1,1] and find what f(x) is for each value? If so, you could use:


x_values = linspace(-1,1,21)
y_values = subs(y,x) 'y is the function in terms of x

yes so if I define my function so:

function y=f(x);
y=(1-6*x^2)^-1;

>> x_values = linspace(-1,1,21)

>> y_values= subs(? ?
 
You might want to look up the syntax for subs. I don't currently have access to matlab, but I'm pretty sure this should work:

syms x;
x_values = linspace(-1,1,21)
y_values = subs((1 − 6x^2)^-1,x)
 
gb7nash said:
You might want to look up the syntax for subs. I don't currently have access to matlab, but I'm pretty sure this should work:

syms x;
x_values = linspace(-1,1,21)
y_values = subs((1 − 6x^2)^-1,x)

I tried but didn`t work I managed to make a functions

function test;

f=inline('(1-6*x^2)^-1');
x_values =linspace(-1,1,21);
for i= 1:21
y_values(1,i)=f(x_values(1,i))

end;

thanks for the linspace code it helped me :]
 

Similar threads

  • · Replies 14 ·
Replies
14
Views
4K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K