Best way to integrate user defined function

daFireman

I would like to evaluate an expression which requires an integral of a user defined function.
I have 3 inputs to the integral expression, E,F and B. F and B are values stored in separate arrays. E is the parameter I would like to integrate over, from a value of 0 to the value of B. I am trying to use the integral function with a user defined function, although I keep getting a matrix dimension error, which I do not comprehend as all the values for F, B (I thought) are being passed as scalar inputs.

However, I realize that for each iteration of the loop I am defining a new function, this seems "inelegant". Any advice as to 1. Why it will not run as is (i.e. the error using *, inner matrix dimensions must agree) 2. Any more elegant solution?

Here is the loop

     for i=1:51
               % DEFINE energy integrand, without prefixes
               nrgInt=@(E,F,B) sqrt(E)*exp(-8*pi*(m*q)^(0.5)*(B-E)/(3*h*F))/(exp(E/(k*Temp))+1);
    % Integrate over energy range, store           
               J(i)=q*mu*8*pi*sqrt(2)*m.^1.5/h^3*Farray(1,i)*integral(@(E)nrgInt(E,Farray(1,i),Barray(i)),0,Barray(i));
               clear nrgInt
        end

Much appreciated

scmg

For your 1st question, because * in Matlab represents matrix operator, so if not both sides of the operation are scalar, then both must have appropriate size, i.e m-by-n matrix * n-by-p matrix

For 2nd question, you can define the function seperately, then use vertorizing instead of for-loop:

J=q*mu*8*pi*sqrt(2)*m.^1.5/h^3*Farray(1,:)*integral(@(E)nrgInt(E,Farray(1,:),Barray(:)),0,Barray(:));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the best way to pass an Excel range to a user defined function?

From Dev

Best way to get user-defined custom name for an Android device

From Dev

Best way to get user-defined custom name for an Android device

From Dev

Best way to integrate go with Spark

From Dev

Best way to integrate NodeJS with Angular

From Dev

Best way to integrate captcha in angularJS

From Dev

Is there a good way to determine if a variable is referencing a user defined function?

From Dev

Best way to trigger a function once after a user is authenticated

From Dev

Best way to integrate Meteorjs, angular and Bootstrap

From Dev

Best way to integrate Spring boot with the Elastic search

From Dev

Best way to authenticate user

From Dev

Best way to alert user

From Dev

.NET: What is the best way to submit a user-defined tag to WebClient's UploadStringCompletedEventHandler

From Dev

.NET: What is the best way to submit a user-defined tag to WebClient's UploadStringCompletedEventHandler

From Dev

Value of a user defined function

From Dev

XSLT User Defined Function

From Dev

Sapply on User Defined Function

From Dev

KeyError: in user defined function

From Dev

User defined function with XMLSERIALIZE

From Dev

Best way to store user settings

From Dev

Best practice for storing enums and user defined values

From Dev

call an SQL User Defined Function Within another User Defined Function

From Java

Best way to integrate webpack builds with ASP.NET Core 3.0?

From Dev

What's the best way to integrate a wordpress blog on my laravel site?

From Dev

Best way to Integrate ADFS 2.0 authentication in a Django application

From Dev

Best way to integrate Vaadin 7 and EJB or how make service layer?

From Dev

The best way to integrate third party library in Android studio

From Dev

Best way to integrate Vaadin 7 and EJB or how make service layer?

From Dev

What is the best way to integrate Pycharm Python into a MySQL CE Database?

Related Related

  1. 1

    What is the best way to pass an Excel range to a user defined function?

  2. 2

    Best way to get user-defined custom name for an Android device

  3. 3

    Best way to get user-defined custom name for an Android device

  4. 4

    Best way to integrate go with Spark

  5. 5

    Best way to integrate NodeJS with Angular

  6. 6

    Best way to integrate captcha in angularJS

  7. 7

    Is there a good way to determine if a variable is referencing a user defined function?

  8. 8

    Best way to trigger a function once after a user is authenticated

  9. 9

    Best way to integrate Meteorjs, angular and Bootstrap

  10. 10

    Best way to integrate Spring boot with the Elastic search

  11. 11

    Best way to authenticate user

  12. 12

    Best way to alert user

  13. 13

    .NET: What is the best way to submit a user-defined tag to WebClient's UploadStringCompletedEventHandler

  14. 14

    .NET: What is the best way to submit a user-defined tag to WebClient's UploadStringCompletedEventHandler

  15. 15

    Value of a user defined function

  16. 16

    XSLT User Defined Function

  17. 17

    Sapply on User Defined Function

  18. 18

    KeyError: in user defined function

  19. 19

    User defined function with XMLSERIALIZE

  20. 20

    Best way to store user settings

  21. 21

    Best practice for storing enums and user defined values

  22. 22

    call an SQL User Defined Function Within another User Defined Function

  23. 23

    Best way to integrate webpack builds with ASP.NET Core 3.0?

  24. 24

    What's the best way to integrate a wordpress blog on my laravel site?

  25. 25

    Best way to Integrate ADFS 2.0 authentication in a Django application

  26. 26

    Best way to integrate Vaadin 7 and EJB or how make service layer?

  27. 27

    The best way to integrate third party library in Android studio

  28. 28

    Best way to integrate Vaadin 7 and EJB or how make service layer?

  29. 29

    What is the best way to integrate Pycharm Python into a MySQL CE Database?

HotTag

Archive