Plotting a Function in MATLAB Using QUAD

Click For Summary
SUMMARY

This discussion focuses on plotting a function in MATLAB using the QUAD function. The correct syntax for the user-defined function 'myfun' is provided, which computes the Bessel function and cosine product. The user is guided to create a vector for omega values and plot the results with a specified line width. The importance of maintaining constant values for the other parameters during plotting is emphasized for clarity in visualization.

PREREQUISITES
  • Understanding of MATLAB syntax and function definitions
  • Familiarity with Bessel functions, specifically 'besselj'
  • Basic knowledge of vector operations in MATLAB
  • Experience with plotting functions in MATLAB
NEXT STEPS
  • Learn about MATLAB function handles and their usage
  • Explore advanced plotting techniques in MATLAB, such as customizing plots
  • Study the properties and applications of Bessel functions in engineering
  • Investigate numerical integration methods in MATLAB beyond QUAD
USEFUL FOR

Mathematics students, engineers, and researchers who need to visualize complex functions in MATLAB, particularly those involving Bessel functions and numerical integration.

ksekoliastis19
Messages
1
Reaction score
0
hello.can anyone help me to plot this function in matlab

Q=quad(@(omeg)myfun(omeg,x,t),-20,20).im not sure if this is correct.my m file function goes like that
function y= @myfun(omeg,x,t)
y=besselj(1,omeg.*x).*cos(omeg.*t).*omeg;


thanks in advance
 
Physics news on Phys.org
Hey-

There are a few problems with the syntax you posted if you are trying to plot the function. For starters, your m-file should look like this:


function y = myfun(omeg,x,t)
y = besselj(1,omeg.*x).*cos(omeg.*t).*omeg;

end

The '@' symbol is used for function handles, and it tells MATLAB which letter is the variable. Now let's make two vectors that we can plot:

x1 = -20:0.1:20;

for i=1:1:max(size(x1))
y1(i)=myfun(x1(i),1,1);
end

plot(x1,y1,'LineWidth',1.5)

Since you have 3 inputs for the original function, we need to keep two constant and plot against the third. In this case, I let the x1 values represent omega, and I gave x and t a default value of 1. You could switch this around easily by changing where the x1(i) is in the loop.
 

Attachments

  • besselj.jpg
    besselj.jpg
    26.1 KB · Views: 492

Similar threads

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