Plotting 2-variable Function with integration using MatLab

조회 수: 3 (최근 30일)
Ganna
Ganna 2014년 9월 19일
답변: Youssef Khmou 2014년 9월 19일
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

답변 (1개)

Youssef  Khmou
Youssef Khmou 2014년 9월 19일
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 ?

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by