Plotting 2-variable Function with integration using MatLab

3 vues (au cours des 30 derniers jours)
Ganna
Ganna le 19 Sep 2014
Does anyone have an example of how to plot a 2-variable function with integration in MatLab (without using MuPAD)?
Here is what I've got:
clear all;
%define a, p and w
a=1; p=1; w=5;
%calculate xmin and xmax
xmin=a-p/2 xmax=a+p/2
%define the coordinates
x=linspace(xmin,xmax); y=linspace(0,1);
%define the coordinates along x-y plane
[x,y]=meshgrid(x,y);
%define and compute the given function along the x-y coordinates
z=w-(1/p)*int((x.-y)^2, x, xamin, xmax) ;
figure surf(y,x,z) title ('a=1 and p=1'); xlabel('w') ylabel('t') zlabel('x') axis tight shading interp colorbar
Clearly, there is something wrong with my function z. The function is
z=w-(1/p)*int(x-t)^2dx where x ranges from a-p/2 to a+p/2

Réponses (1)

Youssef  Khmou
Youssef Khmou le 19 Sep 2014
The problem is in the function int, it is designed for symbolic calculation while your work with numerical one, if you have the function integral you try the following :
clear all;
a=1; p=1; w=5;
xmin=a-p/2; xmax=a+p/2;
x=linspace(xmin,xmax); y=linspace(0,1);
[x,y]=meshgrid(x,y);
L=integral((x-y)^2,1/length(x));
z=w-(1/p)*(L) ;
figure; surf(x,y,z); title('a=1 and p=1'); xlabel('w');ylabel('t');zlabel('x');
Does the result match your prediction ?

Catégories

En savoir plus sur Spline Postprocessing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by