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 Center および File ExchangeSpline Postprocessing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by