Plot the shape of a squid based on mathematical equations
조회 수: 4 (최근 30일)
이전 댓글 표시
The following equations plot a shape of a squid (as seen in the image below). I attempted to code the equations but I think there is something wrong in my code (see code below).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1151225/image.jpeg)
My code is:
clear; close all; clc;
[x,y] = meshgrid(linspace(-1,1,1000),linspace(-1,1,1000));
tot =0;
for i = 1:10
tot = tot + ((100/91) * (0.41 - (1/pi)*atan(25*x - 45)) .* ...
( 0.5 + (1/pi)*atan(25*(x + 0.3 + 0.45*((10*i-55)./45).^20))).* ...
exp(((x.^3./50 + x./4 + ((i-5)./60.*atan(8*x-384/29)) .* ...
(((-1).^(i+1)./20).*cos(5*x)-(i/60)) .*...
(0.475 - x./2 + (x-0.95).^2) .* (pi/2 - atan(40*x-38))-y).^2).*...
(-1500*pi + 3000.*atan(6 - 40.*(x-1.45).^2)) ));
end
f = -0.2 + tot.*(1 - 150*exp(-20*(500*(x-1).^2 + 500*(y-0.25).^2-1).^2));
f(f>0) = 1;
f(f<0) = 0;
contourf(x,y,f,[0 1])
axis equal
map = [1 1 1 ; 0 0 0];
colormap(map)
As you can see this is the plot I got.
Can you please check and let me know where I went wrong?
댓글 수: 0
채택된 답변
Dyuman Joshi
2022년 10월 10일
There are some mistakes while defining tot.
3rd line inside atan it should be 384/25
and the immediate next symbol should be + (addition) instead of .*
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!