Please check My solution
Ältere Kommentare anzeigen
Hi,
this is my first time I am using mathlab please help me by checking my solution if it is okay or not? also please I don't know how to rum the math lab after to see the 3 D OF THE SURGACE after finish the solution.
Q/ Run gardeint ascent , starting at (-1.6, -1.6), with Alfa= 0.2 and 63 iterations for the surface , z =f(x,y)=(e)^(-x^(2 )y^(2)) sinxy, -Pi <= x and x < Pi, -Pi <= y and y < Pi
Soluation:
>> [x,y]=meshgrid(-pi:0.1:pi,-pi:0.1:pi);
>> z=exp(-x.^2*y.^2).*sin(x*y);
>> mesh(x,y,z); axis image;
>> options= {,'interpreter','latex','fontSize',14}; % Use LATEX for labeling
>> xlabel('$x$-axis',options{:}); ylabel('$y$-axis',options{:});
>> title('ASCENT',options{:});
>> hold on
>> p=[-1.6,-1.6];
>> plot(p(1,1),p(1,2),'or','MarkerSize',10);
>> for i=1:63
x=p(1,size(p,2));
y=p(2,size(p,2));
fx=-2*x*y^2*exp(-x^2*y^2)*sin(x*y);
fy= -2*x^2*y*exp(-x^2*y^2)*sin(x*y);
p=[p p(:,size(p,2))+0.2*[fx;fy]]; % the only line that really maters
x=p(1,:); % so that you copy z componenet copy from maple
y=p(2,:);
plot(p(1,:),p(2,:),'k.-','MarkSize',7);
stem3(p(1,:),p(2,:),exp(-x.^2*y.^2).*(sinx*y),'b-+');
>> 'end'
3 Kommentare
Walter Roberson
am 8 Sep. 2019
No,
y=p(2,size(p,2));
p(2,2) does not exist on the first iteration.
p=[-1.6,-1.6];
I would suggest to you that you are using the second column to store the y coordinates, instead of the second row
x = p(i, 1);
y = p(i, 2);
Yousif Hamzah
am 9 Sep. 2019
Walter Roberson
am 9 Sep. 2019
You assign
p=[-1.6,-1.6];
That makes p a 1 x 2 scalar.
plot(p(1,1),p(1,2),'or','MarkerSize',10);
That statement is okay because p(1,1) and p(1,2) both exist.
for i=1:63
x=p(1,size(p,2));
That statement is okay because size(p,2) is 2 because p is 1 x 2, and p(1,(2)) exists.
y=p(2,size(p,2));
size(p,2) is 2 because p is 1 x 2, so you are asking to access p(2,2), but p is only 1 x 2 so that will fail.
do yiu mean x= (pi,1);
No, that would be invalid syntax.
x = (pi,1)
↑
Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
You cannot have (expression,expression) in MATLAB, except in the context of indexing or passing parameters to functions.
It is not obvious to me why you would think that the transcendtal constant π would be useful for your calculations.
Antworten (0)
Kategorien
Mehr zu Axis Labels finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!