[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1917
  • Last Modified:

Evaluating a double integral in Matlab

I have a function of four variables (x,y,t,k) and want to evaluate the finite integral with respect to two of them (t and k) and plot the resulting function with respect to x and y. How can I do this using Matlab?

My function is as follows:

f = k * exp(-k^2*1/2) * cos( x * k * cos(t) + y * k * sin(t) )

I want to evaluate the double integral with (0 < t < 2pi) and (1 < k < 2) and plot the resulting function with respect to x and y.

Can anybody help me?
Thanks :)
T
0
tryso
Asked:
tryso
  • 4
  • 4
  • 2
1 Solution
 
aburrCommented:
I am nmore familier with MathCad than Mathlab. So you want your plot to be a 3-D plot of f(x,y) vs x and y?
0
 
trysoAuthor Commented:
Yes,

Which way you plot it is not the main issue though, it might just as well be a contour plot, or even a plot along one axis.

Regards,
Trygve
0
 
aburrCommented:
Yes, I just wanted to make sure I understood what you were looking for. Unfortunately I am not familiar with matlab, just MathCad, so I cannot help you much.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
The_TCommented:
Hey,
This is the fastest solution I can come up with. Maybe not the best one.

Create a M-file of your function like this: replacing x<->i, y<->j

function z = integrand( k,t)
global x y i j
z=k .* exp(-k.^2*1/2) .* cos( x(i) * k .* cos(t) + y(j) * k .* sin(t) );

now, in your main program write this:



global x y i j %for global variables
x=[0:0.5:1]; %Anything you want for your res
y=[0:0.5:2]; %again, anything you want

Q=zeros(length(x),length(y)); %zeros matrix

for i=1:length(x)
   for j=1:length(y)
      Q(i,j) = dblquad(@integrand, 1, 2i, 0, 2*pi);
   end
end
Q



now you have a matrix Q witch you can plot or do what ever you want with it.
Hope it helps.
* take into considaration that this are "for" loops so it may take some time.
I checked it on matlab 6.5 and it work good.
0
 
The_TCommented:
*** 2 Correction:
1) ignore the comment: "replacing x<-> i....." on the 3rd row.
2) I mistakely wrote '2i' in the dblquad function so change it to 2.
0
 
aburrCommented:
The complete MathCad solution ito your problem is available at
www.temp.qzxservices.com.
-
I thought that the mathCad solution would be simpler, but I am not very familiar with Matlab. Therefore I was quite interested in the Matlab solution. As you can see the MathCad solution is much simpler. I had not realized how much simpler.

The link goes to the solution with graph and includes the complete programing for the solution.
0
 
The_TCommented:
True,
Your solution looks pretty simple. But, they are actually the same solutions only Matlab is a programming language and MathCad is a CAD program.
I used MathCad alot when started University but pretty soon I had to start using Mathematica and Matlab as they were much more powerful.
I recommend you try one of them. They may look very different at the begining but after some time you get used to them.
0
 
aburrCommented:
Of course they are the same solution. If not, one would be wrong.
I am not sure what you mean by saying that MathCad is a CAD program while the others are a programing language. If you want, you can insert a section in a language like C++ into Mathcad. Mathcad started out as only a numberical solution program but it now incorportaes Maple for symbolic solutions.
Mathematica does have the (deserved) reputation of being the most powerful math program. Matlab is very popular and I will take your word that it is more powerful, especially if you make full use of its matrix orientation.
There is somethig to be said for simplicity and transparentcy, however (especially when coupled with a lot of power).
0
 
The_TCommented:
I'll explain what I meant,
You said yourself: "you CAN insert...".
Now, in Matlab you don't have much choice since it is just a programing language. That might make some people prefer Mathematica or MathCad - which is still the most easy and simple math program I dealt with but was somewhat weak for advanced mathematical needs.
0
 
trysoAuthor Commented:
Thank you The_T

That was what I needed for my calculations

Tryso
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now