Matlab help fplot() with 3-input argument function?

Click For Summary
SUMMARY

The discussion centers around using the MATLAB function fplot() with a custom function that requires three input arguments. The user encountered limitations with fplot(), which only accepts functions with a single input variable. Instead, they successfully utilized the plot() function to visualize the output of their custom function myfun3(), which computes a Gaussian-like output based on the provided parameters. The user demonstrated how to call the function with varying input values, achieving the desired plot without using fplot().

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with function input arguments in MATLAB
  • Knowledge of plotting functions in MATLAB, specifically plot() and fplot()
  • Basic understanding of Gaussian functions and their properties
NEXT STEPS
  • Explore the differences between fplot() and plot() in MATLAB
  • Learn how to create custom functions in MATLAB with multiple input arguments
  • Investigate MATLAB's nargin function for handling variable input arguments
  • Study advanced plotting techniques in MATLAB for better data visualization
USEFUL FOR

Students, educators, and professionals working with MATLAB who need to visualize functions with multiple input parameters, particularly in mathematical modeling and data analysis contexts.

asdf12312
Messages
198
Reaction score
1
matlab halp! fplot() with 3-input argument function??

Homework Statement


heres da link: http://postimg.org/image/uqqr3q0k3/

don't really need to look at that though. Its just a function in another file, I have to call it but it takes 3 input variables, problem with fplot is it only uses a function with one input variable (i.e. x).. and i (think??) that the function has to plot the values that is the output to the equation. so inside it after it calculates it would plot the points so I would probably the plot would already be given when I call the function..?? For the hint 'fplot' was given so I was confused. I actually solved it without use of fplot (plot instead) but here is the basic:

with 2 input variables are constant, so only one is varying (x). which is range of numbers with step size. so here is my MATLAB code which i will post ni next section. also i could have done it another way, set an output for the function that would be the range of values. but there is no output at all except the plot graph, since the ? didnt ask about it.

Homework Equations



Code:
function [] = myfun3( x, m, s)
if nargin==1
    m=2.5;
    s=0.8;
end

out=(1/(s*sqrt(2*pi)))*exp(0.5*((x-m)/s).^2);
plot(out);title(['g(x) for values x=',num2str(min(x)),' to x=',num2str(max(x)), ' with step=',num2str(x(max(x))-x(max(x)-1)),', m=',num2str(m),', s=', num2str(s)]);
end

to call it i type:
myfun3(0:0.05:5,2.5,0.8) or myfun3(0:0.05:5)

The plot I got for this I have below, think this is right:
http://postimg.org/image/o50e9d0tr/
 
Last edited:
Physics news on Phys.org
Bump please..help me
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K