Help with Integral and MATLAB Equation using Real Numbers

In summary, the conversation discusses a physics experiment that uses MATLAB code to analyze the problem. The code produces results, but the numbers used are nonsensical and need to be reworked with real numbers. The main issue is using very large numbers, and the goal is to make the exponential component determine the number of rings. However, the rest of the constants need to be normalized for this to occur.
  • #1
Lemenks
14
0
I carried out a physics experiment and I wanted to analysis the problem with matlab. I have some code in MATLAB that "works" as in it gives ok result but the numbers used are quite nonsensical, I need help making the reworking the equation with real numbers. I am not sure if this is the correct thread, if not sorry. Here is my code:

Matlab:
format long;
clear all;

I0=39546.95973;
i=sqrt(-1);
r=0.0;
fid=fopen('plot.txt','w')  %Êý¾ÝдÔÚplot.txt
for m=1:300
    p(m)=m*0.0001-0.015;   %¿ÉÒÔµ÷Õû×÷ͼ²½³¤
    In(m)=0;
    dddr=0.00001;
    for r=0.0:dddr:0.010   %¸ù¾ÝÊÕÁ²ÐÔµ÷Õû»ý·ÖÉÏÏ޺Ͳ½³¤
        In(m)=In(m)+r*besselj(0,5500000*r*p(m))*exp(-4.325259515570934*10^6*r*r)*exp(-i*(5500000*r*r-27.014528191562999*exp(-4.325259515570934*10^6*r*r)));
    end
    I(m)=3.025*10^13*dddr^2*I0*(norm(In(m)))^2;
    fprintf(fid,'%9.4f  %9.4f  \n',p(m),I(m));
end
fclose(fid)
fclose all;
hold off
    plot(p,I);  %»Í¼
hold on
return;

My main problem is using very large numbers like "5500000". What I would like to do, is make the exp(a*exp(b*r^2)) component be the part of the function that determines the number of rings, where a=2Npi and N would determine the number of rings. However I am not sure how to go about normalizing the rest of the constants so that this would be the case.

Mod note: I added code tags. Please do that every time you post code.
 
Physics news on Phys.org
  • #2
You will have to give more details. What physical problem are you looking at? What is the code actually doing?
 

FAQ: Help with Integral and MATLAB Equation using Real Numbers

How do I use MATLAB to solve an integral using real numbers?

To solve an integral using real numbers in MATLAB, you can use the "integrate" function. This function takes in the integrand, the variable of integration, and the limits of integration as inputs. For example, to solve the integral of f(x) = x^2 from 0 to 5, you would use the command "integrate(@(x) x^2, 0, 5)".

What is the syntax for writing an integral equation in MATLAB?

The syntax for writing an integral equation in MATLAB is "integrate(@(variable) integrand, lower limit, upper limit)". The "@(variable)" part specifies the variable of integration, and the integrand is the function being integrated. The lower and upper limits are the boundaries of the integral.

Can I use symbolic variables in my integral equation in MATLAB?

Yes, you can use symbolic variables in your integral equation in MATLAB. This allows you to solve integrals with unknown parameters or variables. To use symbolic variables, you need to use the "syms" command and define the variable before using it in the integral equation.

Is it possible to plot the graph of an integral equation in MATLAB?

Yes, you can plot the graph of an integral equation in MATLAB using the "ezplot" function. This function takes in the integrand, the variable of integration, and the limits of integration as inputs and plots the graph of the integral. For example, to plot the graph of f(x) = x^2 from 0 to 5, you would use the command "ezplot(@(x) x^2, 0, 5)".

Are there any other helpful functions in MATLAB for solving integrals?

Yes, there are other helpful functions in MATLAB for solving integrals, such as "quad" and "quadl". These functions use advanced numerical methods to approximate the value of an integral. Additionally, the "diff" function can be used to find the derivative of a function, which can then be integrated using the "integrate" function.

Similar threads

Replies
2
Views
3K
Replies
9
Views
4K
Replies
1
Views
1K
Replies
2
Views
4K
Replies
1
Views
3K
Replies
41
Views
9K
Replies
1
Views
2K
Replies
4
Views
3K
Back
Top