Matlab m file function with multiple variables

Click For Summary
SUMMARY

The discussion focuses on integrating a MATLAB function with multiple variables, specifically how to pass parameters 'a' and 'b' to the function 'myfun' during integration. The correct method to achieve this is by using an anonymous function: R=quadgk(@(t)myfun(t,a,b),0,Inf). This allows the integration to properly utilize the external variables 'a' and 'b'. Additionally, a separate issue regarding a timer in a MATLAB GUI was raised, but the primary resolution pertains to the integration method.

PREREQUISITES
  • Understanding of MATLAB function syntax
  • Familiarity with MATLAB's quadgk function for numerical integration
  • Knowledge of anonymous functions in MATLAB
  • Basic concepts of MATLAB GUI programming
NEXT STEPS
  • Explore MATLAB anonymous functions for parameter passing
  • Learn about MATLAB's quadgk function and its options
  • Investigate advanced MATLAB GUI timer functionalities
  • Study MATLAB function handles and their applications
USEFUL FOR

MATLAB users, particularly those involved in numerical analysis, function integration, and GUI development, will benefit from this discussion.

strokebow
Messages
122
Reaction score
0
Hi,

I have a MATLAB function m file and I want to integrate the function.

Code:
function y = myfun(t,a,b)

y = (1/(2*pi)).*(1./t)*(1i*(a+b));
end
Then when I call the integration in MATLAB I don't know how to specify a and b whilst integrating over t.

I need to be able to set a and b outside of the function m file and then call the integral.

R=quadgk(@myfun,0,Inf)
This command will not work. a and b need to be set. I want to set a and b (this can vary) and then run the integral. I have tried set a and b in the MATLAB workspace but that still doesn't work.

Please can anyone help?
** Also, please let me know if my explanation is not clear?

Thanks
 
Last edited:
Physics news on Phys.org
Solved it.

Its how you call the function.

It should be:

R=quadgk(@(t)myfun(t,a,b),0,Inf)

simples.
 
hi to all
I have a problem with timer in gui in matlab
i want to to show real time in gui figure but when run the timer mfile it create a new figure
seperatly from main figure

any one can help me?
if know a way for this problem please help me ...
my email address is : mhmz66@yahoo.com
tnx so mucho:)
 

Similar threads

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