x = linspace(0,1,50);
y = linspace(0,1,50);
i = x(1);
j = y(1);
for i < length(x)
for j < length(y)
u(i,j) = (1/sinh(-pi))*sin(pi*y(j))*sinh(pi*(x(i)-1));
j = j+1;
end
j = y(1);
i = 1 + i;
end
surf(u, x, y)
File: visualization_hmw_3_q_1.m Line: 6 Column: 7
Invalid use of operator.

댓글 수: 4

Thomas Murdoch
Thomas Murdoch 2022년 3월 1일
I recently solved this problem and want to visualize the function 'u'. I for some reason cannot resolve the '<' error
Star Strider
Star Strider 2022년 3월 1일
See if the while approach will produce the desired result. I believe you are confusing it with for.
The while approach did work. I have attached my complete code here:
clear all
close all
x = linspace(0,1,50);
y = linspace(0,1,50);
i = 1;
j = 1;
while i <= length(x)
while j <= length(y)
u(i,j) = (1/sinh(-pi))*sin(pi*y(j))*sinh(pi*(x(i)-1));
j = j+1;
end
j = 1;
i = 1 + i;
end
surf(x, y, u)
Walter Roberson
Walter Roberson 2022년 3월 1일
Is there a particular reason to use while there instead of for ? When you are doing a fixed number of iterations, for is almost always cleaner to code.

댓글을 달려면 로그인하십시오.

 채택된 답변

David Hill
David Hill 2022년 3월 1일

0 개 추천

x = linspace(0,1,50);
y = linspace(0,1,50);
u=zeros(50);
for i =1:length(x)
for j =1: length(y)
u(i,j) = (1/sinh(-pi))*sin(pi*y(j))*sinh(pi*(x(i)-1));
end
end
surf(x, y,u)

댓글 수: 1

Alternatively,
[x,y]=meshgrid(linspace(0,1,50));
u = (1/sinh(-pi))*sin(pi*y).*sinh(pi*(x-1));
surf(u,x,y);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2022년 3월 1일

댓글:

2022년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by