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

In summary, the conversation discusses a project to make an integral with MATLAB, but the code keeps giving an error. The error is caused by using incorrect functions, and there is a question about plotting with an unknown function. The code for this is unclear.
  • #1
davidaholic
1
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
  • #2
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.
 

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

1. Can I use Matlab to solve integrals?

Yes, Matlab has built-in functions for solving integrals. The most commonly used function is int(), which allows you to specify the function to integrate, the limits of integration, and any additional parameters.

2. How do I define a function in Matlab for integration?

You can define a function in Matlab using the function keyword, followed by the input and output variables and the function body. For example, function y = f(x) defines a function called f that takes in an input variable x and returns an output variable y.

3. How do I plot the integral in Matlab?

After solving the integral using the int() function, you can plot the result using the plot() function. This will produce a graph of the integral function, with the limits of integration as the x-axis.

4. Can I use symbolic variables in Matlab to solve integrals?

Yes, you can use symbolic variables in Matlab to solve integrals. This allows you to represent variables like x and y in your integral function, instead of assigning them specific numerical values.

5. How do I check the accuracy of the integral result in Matlab?

Matlab has a built-in function called integral() that allows you to specify the desired accuracy for the integral. This function uses adaptive quadrature to estimate the integral and will return an error estimate, which you can use to check the accuracy of the result.

Similar threads

Replies
5
Views
2K
Replies
11
Views
2K
Replies
11
Views
3K
Replies
4
Views
1K
Replies
1
Views
7K
Replies
3
Views
2K
Replies
1
Views
4K
Back
Top