What is the Code for Plotting with an Unknown Function in Matlab?

  • Context: MATLAB 
  • Thread starter Thread starter davidaholic
  • Start date Start date
  • Tags Tags
    Integral Matlab
Click For Summary
SUMMARY

The forum discussion centers on resolving errors in MATLAB code related to integrating and plotting functions. The user encounters an "Undefined function or method" error when attempting to define functions using 'f=@x;' and 'f=@y;'. The correct syntax for anonymous functions in MATLAB is 'f = @(x) x' and 'f = @(y) y'. Additionally, the user seeks guidance on plotting with an unknown function, indicating a need for further clarification on the variable 'pilihan'.

PREREQUISITES
  • Familiarity with MATLAB programming language
  • Understanding of anonymous functions in MATLAB
  • Knowledge of numerical integration methods in MATLAB, specifically the 'quad' function
  • Basic concepts of plotting functions in MATLAB
NEXT STEPS
  • Learn about MATLAB anonymous functions and their syntax
  • Explore the 'quad' function for numerical integration in MATLAB
  • Research how to plot functions in MATLAB using the 'plot' function
  • Investigate handling user input and callbacks in MATLAB GUI applications
USEFUL FOR

Students, researchers, and engineers working with MATLAB who need to perform numerical integration and plotting of functions, especially those dealing with user-defined or unknown functions.

davidaholic
Messages
1
Reaction score
0
******urgent

i have a project to make a integral with matlab
when i make a code i have an error. this is the code

f = str2double(get(edit1,'string'));
a = str2double(get(edit2,'string'));
b = str2double(get(edit3,'string'

chose = get(popup1,'value');
switch pilihan
case 1
f=@x;
case 2
f=@y;
end;

f=quad(f,a,b);

if a >= b
disp('you.re wrong!');
end

and i get error in

? Undefined function or method 'x' for input arguments of type 'double'.

Error in ==> quad at 77
y = f(x, varargin{:});

Error in ==> luas1b at 13
f=quad(f,a,b);

? Error while evaluating uicontrol Callback

and i want to ask 1 more if i want to plot with unknown function do you know what is the code
 
Physics news on Phys.org
You've not given us half of the data. What is pilihan?

These are wrong:
davidaholic said:
f=@x;
davidaholic said:
f=@y;
They should have been:
f = @(x) x
f = @(y) y
davidaholic said:
if i want to plot with unknown function do you know what is the code
Not clear what you're trying to say.
 

Similar threads

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