loop explanation applied in equations solution

9 ビュー (過去 30 日間)
Michael
Michael 2023 年 4 月 29 日
回答済み: Neha 2023 年 5 月 3 日
Hi
I currently learning to solve math equations using matlab.Could you explain me the loop below?
thanks
while check~='y'
x0y0=input(['Dwse mou ta akraia shmeia ths grafikhs parastashs\n ' ...
'sth morfh [x0 xend y0 yend] : ']);
xstart=x0y0(1);xend=x0y0(2);ystart=x0y0(3);yend=x0y0(4);
e=10^(-14);
x=linspace(xstart,xend,60);
y=linspace(ystart,yend,60);
[X,Y]=meshgrid(x,y);
Z1=f(X,Y);
Z2=g(X,Y);
contour(X,Y,Z1,[0 0],'m')
hold on
contour(X,Y,Z2,[0 0],'b')
hold off
check=input('Eisai euxaristhmenos apo th grafikh parastash?','s');
end

回答 (1 件)

Neha
Neha 2023 年 5 月 3 日
The code creates a while loop that allows the user to input the boundaries of a graphical representation of a mathematical function and plot it with contours.
Inside the while loop, the input values are assigned to variables 'xstart', 'xend', 'ystart', and 'yend'.
The 'linspace' function is used to create a vector x of 60 equally spaced points between 'xstart' and 'xend', and a vector y of 60 equally spaced points between 'ystart' and 'yend'.
The 'meshgrid' function returns 2-D grid coordinates based on the coordinates contained in vectors x and y. X is a matrix where each row is a copy of x, and Y is a matrix where each column is a copy of y. The grid represented by the coordinates X and Y has length(y) rows and length(x) columns.
After f and g functions return Z1 and Z2, the 'contour' function is used to plot the contour lines of Z1 and Z2 where the contour level is 0 (contour lines are drawn at a single height- 0).
The 'm' and 'b' arguments specify the colors of the contour lines.
For detailed explanation about contour' and 'meshgrid' functions, please refer to the following documentation:

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by