Making functions with 'inline' command in matlab

  • Context: MATLAB 
  • Thread starter Thread starter nottern
  • Start date Start date
  • Tags Tags
    Functions Matlab
Click For Summary
SUMMARY

The discussion centers on using the 'inline' command in MATLAB to define a function for integration. The user initially defined the function as f=inline('1/sqrt(1-0.25*sin(x)^2)'), which led to errors during integration attempts with the quad command. A solution was provided by modifying the function definition to f=inline('1./sqrt(1-0.25*sin(x).^2)'), correcting the syntax to ensure element-wise operations are performed, thus resolving the integration issue.

PREREQUISITES
  • Understanding of MATLAB syntax and commands
  • Familiarity with the 'inline' function in MATLAB
  • Knowledge of numerical integration techniques in MATLAB, specifically the quad command
  • Basic understanding of mathematical functions and their representations in programming
NEXT STEPS
  • Learn about MATLAB's anonymous functions as an alternative to 'inline' functions
  • Explore MATLAB's integral function for numerical integration
  • Study element-wise operations in MATLAB to avoid common syntax errors
  • Investigate error handling in MATLAB to troubleshoot function integration issues
USEFUL FOR

MATLAB users, particularly those involved in numerical analysis, engineering students, and anyone looking to improve their skills in function integration within MATLAB.

nottern
Messages
3
Reaction score
0
hi everybody... I'm new here, and I'm here 'cause I'm having some trouble with matlab
i was trying to integrate a function, so i first defined the function with the inline command:
f=inline('1/sqrt(1-0.25*sin(x)^2)')
now MATLAB says nothing if you write the function with this command, but it makes it after, when you decide to do some operation... that happens to me when i try to integrate using the quad command, and MATLAB throws those red letters saying Error...
i may be making some syntaxis mistakes, that's why I'm asking here for some help

by the way, i want to do this integral
\int_0^{\frac{\pi}{2}} \frac{ds}{\sqrt{1-0.25\sin^2(s)}}
thanks
 
Last edited:
Physics news on Phys.org
nottern said:
hi everybody... I'm new here, and I'm here 'cause I'm having some trouble with matlab
i was trying to integrate a function, so i first defined the function with the inline command:
f=inline('1/sqrt(1-0.25*sin(x)^2)')
now MATLAB says nothing if you write the function with this command, but it makes it after, when you decide to do some operation... that happens to me when i try to integrate using the quad command, and MATLAB throws those red letters saying Error...
i may be making some syntaxis mistakes, that's why I'm asking here for some help

by the way, i want to do this integral
\int_0^{\frac{\pi}{2}} \frac{ds}{\sqrt{1-0.25\sin^2(s)}}
thanks

try
f=inline('1./sqrt(1-0.25*sin(x).^2)')
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K