Graphing in MATLAB: Suitable Domain for f & g

  • Context: MATLAB 
  • Thread starter Thread starter roam
  • Start date Start date
  • Tags Tags
    Graphing Matlab
Click For Summary

Discussion Overview

The discussion revolves around graphing two functions, f and g, in MATLAB, focusing on determining a suitable domain for both functions and addressing errors encountered during graphing. The scope includes technical explanations of MATLAB syntax and function behavior.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks clarification on a suitable domain for the functions f = (2+x)/((x-2)(x+1)) and g = 1/sqrt((2x^2 - 1)(x^2-1)), noting the individual domains of f and g.
  • Another participant reports errors encountered when attempting to graph function g, questioning the correctness of their MATLAB code.
  • A participant explains the need for element-wise operations in MATLAB, detailing how to create a vector of values and apply the function to each element.
  • There is a question about the purpose of the dot notation in MATLAB, specifically regarding element-wise division and exponentiation.
  • Clarifications are provided regarding the syntax and the importance of specifying a suitable domain for better visualization of the graph.
  • Participants discuss the concept of a suitable domain, suggesting that it involves selecting appropriate bounding box limits for the graph.

Areas of Agreement / Disagreement

Participants express varying opinions on what constitutes a suitable domain for the functions, and there is no consensus on the specific domain to use. Additionally, there are differing views on the interpretation of MATLAB syntax and its implications for graphing.

Contextual Notes

Participants mention potential issues with automatic range selection in MATLAB for the functions discussed, indicating that manual specification of limits may be necessary due to the nature of the functions.

roam
Messages
1,265
Reaction score
12
Hi!

For those of you who know how to use Matlab, I want to graph two functions f = [tex]\frac{(2+x)}{(x-2)(x+1)}[/tex] and g = [tex]\frac{1}{\sqrt{(2x^2 - 1)(x^2-1)}}[/tex]

On my instructions sheet it says; draw f and g on the same grid on a "suitable" domain.

The domain of f is all the real numbers except for 2 & -1

The domain of g = [-2,∞)\{±1}

What is a suitable domain for both functions to put on the graph AND what's the code for specifying the domain in MATLAB?

could it be: x≥-2\±1 ∩ x = R\{2,-1}?
 
Last edited:
Physics news on Phys.org
I also need to mention that when I'm trying to graph g=[tex]\frac{1}{\sqrt{(2x^2 - 1)(x^2-1)}}[/tex] I get errors. My code was;

>> syms x
>> ezplot 1/sqrt[(2x^2-1)*(x^2-1)]

I'm sure this is the right code for it so what's wrong?
 
In Matlab, everything is vectors of numbers. So, you might do,

xx = -2:.1:10;
g = 1./sqrt((2*xx.^2-1).*(x.^2-1));
plot(xx,g)
axis([-2 4 -2 6])

This basically says,
1) make a list of numbers called xx starting at -2, increasing by .1 each increment until 10. ie: -2, -1.9, -1.8, etc

2) Make a list of numbers called g whose first value is the equation applied to the first element of xx, second value is the equation applied to the second element of xx, etc. The reasin there are little period dots in there (.* instead of *, ./ instead of /, .^2 instead of ^2), is that tells MATLAB to do the calculations element by element. Otherwise it might interpret xx*xx to mean take the dot product between the vectors or something like that. Adding the .'s makes sure any operation stays elementwise.

3) plot the list of xx coordinates against the list of g values

4) change the x and y mins and maxes on the graph for a better picture. (xmin = -2, xmax = 4, ymin = -2, ymax = 6)
 
Btw, when you write "g = 1./sqrt((2*x.^2-1).*(x.^2-1))", what's the point of having a dot after the x and 1? like 1. & x.


The graph now looks something like http://img523.imageshack.us/img523/5479/40023260kg1.gif" Although the instruction is to draw it on a suitable domain... how do I do that?
 
Last edited by a moderator:
It's not after the 1, but rather before the division sign: ./
Same thing for the x, its not after the x, its before the exponent sign: .^

By the way typo above the single x should be xx, or whatever you name it.

A suitable domain means you choose where to zoom in on the graph by choosing the bounding box limits for x and y
 
What's the role of the dot that comes before the division sign/exponent sign?

So, what "suitable domain" would you think is right to choose? What are the codes for doing this?
 
Last edited:
Normally a/b means to the matrix "division". Ie: a*(b inverse). What you want is to divide element by element, so that you put the dot in there to tell MATLAB so. Same thing with exponentiation.

The way to choose the domain is specifing the minimum and maximum x and y values for the graph, which you do with the code:
axis([xmin xmax ymin ymax])

Matlab will automatically guess these values if you don't specify them, but for this function automatic range doesn't work well.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K