integral solving syntax for new MATLAB users

1 Ansicht (letzte 30 Tage)
Fatima Amin
Fatima Amin am 2 Okt. 2020
Kommentiert: Fatima Amin am 2 Okt. 2020
how can I write the syntax for this integral in MATLAB ?
I am solving a system of coupled non linear equations and I am new to MATLAB
  3 Kommentare
John D'Errico
John D'Errico am 2 Okt. 2020
This is a little confusing, because you seem to be writing g as a function of x1, but in reality, it is a function of t, and possibly t0, and for that matter, gamma. x1 is apparently some unknown function, though I assume it is known to you. What form does x1 take?
It also brings up the issue of how can we know what you know, or don't know. If you know absolutely nothing, then someone needs to teach you everything. So, do you know how to write a function? Do you know what function handles are, how to use them? If not, then you need to do some reading, since they will be crucial to your progress.
A lot of the time, it is far easier for someone to help you if you have made an attempt to do it already, since then someone needs only to correct what you did wrong. It also gives us an idea of what you already understand.
If you really have no clue how to do integration, then you will gain a huge amount by learning to use the three fundamental tools in MATLAB for integration, thus trapz, integral, and int.
trapz - does numerical integration of a function given in the form of points along a curve. Trapezoidal rule, so not very good, but good in the presence of potential noise.
integral - numerical integration as a definite integral, accuracy determined by a tolerance. integral does NOT apply when symbolic variables are present. So it will not provide an integral as a function of some general unknown parameter. There are also double and triple integration forms of this tool.
int - symbolic integration tool, requires the symbolic toolbox.
And this should point out the next question - what toolbox do you have? Thus int only exists for you if you have the symbolic toolbox, whereas the other tools are part of MATLAB itself. In many cases when you ask a question, it even helps to tell people what release of MATLAB you have, since then we can know if something cannot be done in an older release.
Anyway, if I were you, I would spend some time playing with integral, and the other tools. Learn to use the tool. Test it on a simple kernel function where you know the answer. Verify that you undertand how it works. That really is the best way to learn.
Finally, I'd point out that you want to avoid naming your variable gamma, since gamma is a highly useful function. At least it may be useful to you at some point.
Fatima Amin
Fatima Amin am 2 Okt. 2020
actually i am trying to solve a system of coupled non linear equations

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 2 Okt. 2020
x1 = @(tau) tau.^2; % define x1(tau)
gamma = 1;
t0 = 0;
t = 2;
int_term = @(tau) exp(-gamma*(t-tau)).*x1(tau);
g = integral(int_term, t0, t);

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by