2D plot of a function WITH MATLAB

Click For Summary

Discussion Overview

The discussion centers around generating a 2D plot of a mathematical function using MATLAB, specifically focusing on how to vary a parameter 's' while keeping 'x' within a defined range. Participants explore different coding approaches and syntax issues related to MATLAB plotting.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant presents a function involving 'y(x,s)' and seeks guidance on how to change the 's' value dynamically in MATLAB.
  • Another participant suggests using a for loop to iterate over 's' values and plot the function for each iteration.
  • There is a request for clarification regarding the implementation of the loop and the plotting commands in MATLAB.
  • A different approach is proposed, where a participant shares a code snippet using Freemat, demonstrating how to plot multiple lines for varying 's' values.
  • One participant encounters an error related to defining the function and seeks assistance with the correct syntax.
  • Another participant provides suggestions for correcting the function definition, including using 'atan' instead of 'arctan' and alternative methods for exponentiation in MATLAB.

Areas of Agreement / Disagreement

Participants express varying levels of clarity regarding the implementation of the plotting commands, and there is no consensus on the best approach to define the function or resolve the encountered errors.

Contextual Notes

Some participants mention specific errors encountered, such as 'm power error', and suggest alternative coding practices without resolving the underlying issues.

Who May Find This Useful

This discussion may be useful for individuals learning MATLAB, particularly those interested in plotting functions with variable parameters and troubleshooting common coding errors.

aredy29
Messages
10
Reaction score
0
My function is;

y(x,s)= 1-(cos[(s-1)arctan(x)]*gamma(s-1))/(1+x^2)^(s-1)/2

varible x will have range from 0 to 10. At one time the s value will be constant e.g. s = 3 but I want to change s for different values( is there any commands in MATLAB that will allow me to do this ?). I tried many time but can't get it.
 
Physics news on Phys.org
still not clear..
 
The idea is to construct a loop to generate the s values say from 0 to 5:

for s = 1:5
x=0:10
y=s*x.*x
plot(x,y)
hold all
end
 
how should I define my function ? I keep getting 'm power error'
 
Here's an example I did in Freemat, a MATLAB clone, as I don't use MATLAB much anymore

for i = 1:5
s=i
x=0:10
y=s*x
plot(x,y)
hold('on')
end

It draws five plots on one chart with varying s values.
 
for your eqn arctan should be atan and for x^s powers you could use power(x,s)

alternatively x^2 = x.*x dots x to x to get a vector of x^2 values
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K