이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to plot parametric equations by using "for loop"
조회 수: 4 (최근 30일)
이전 댓글 표시
Wajahat
2017년 5월 18일
If we have,
t= linspace (-30,-1.6);
X= ((3*t)./(1+t.^3);
Y= ((3*t.^2)./(1+t.^3));
plot(X,Y);
How we plot X and Y by using for loop?
댓글 수: 18
Wajahat
2017년 5월 18일
Actually, i want to plot a matrix equations. To plot matrix equations we use for loop.
Wajahat
2017년 5월 18일
편집: Guillaume
2017년 5월 18일
t= linspace (-30,-1.6);
q=linspace (-30,-1.6);
X= ((3*i*t)./(1+t.^3);
Y= ((3*i*t.^2)./(1+t.^3));
a=[X Y; -Y X];
b=[X Y; -conj(Y) conj(X)];
c=[X X; -Y Y];
q1=q-(det(a)./det(b));
u1=-(det(c)./det(b));
plot(q1,u1)
now we have matrix a, b and c. How we plot it using for loop?
KSSV
2017년 5월 18일
This gives error because, det exists for square matrices...in this a is not square matrix.
Rik
2017년 5월 18일
a is not square with the above code, it is 2x200.
And when you want to plot something, it is at least as important to think about how you want to plot as what you want to plot. What do you want to be on what axis? Do you want to show more information using marker sizes or colors?
With a, b and c, you could make a 3D scatter plot (or surface plot) with the values in a, b and c as the x, y and z values. Is that what you want?
Wajahat
2017년 5월 18일
without using for loop, it gives error (i.e. one of the matrix would not be a square), my question is, how to plot parametric equations with for loop?
KSSV
2017년 5월 18일
And I would like to point put that determinant of a=[X Y; -Y X] would be always zero, even though you make it a square. We cannot help you unless your question is clear.
Guillaume
2017년 5월 18일
Wajahat, We really have no idea what it is you're asking. You started with:
if we have [parametric equation and code that plots it given], how we plot X and Y by using for loop?
To which you were told: It's already working, why do you want to use a loop?
You then changed your question to say that you had a matrix instead. Again, said you needed to use a loop without explaining why. When asked why you wanted to use a loop, you gave some code that did not even work.
You've now changed your question again back to the original question. Our answer is still the same: It's already working, why do you want to use a loop?
We have no idea why you insist on using a loop. You haven't showed us why a loop is needed and we have no idea what it is you want looping over.
Wajahat
2017년 5월 19일
편집: Wajahat
2017년 5월 19일
Guillaume, i have written a code (below) in which a matrices a and b are involved and get the plot of a solution q1 by using loop.
clear all;
close all;
x=-10:.1:10;
t=-10:.1:10;
q=.2;
mu1=4-.3*i;
mu2=.3+i;
for k=1:length(x)
for l=1:length(t)
x11=exp(i.*x(k)./(2*mu1)).*exp(-i.*mu1.*t(l)./2);
x21=exp(i.*x(k)./(2*mu2)).*exp(-i.*mu2.*t(l)./2);
y11=exp(-i.*x(k)./(2*mu1)).*exp(i.*mu1.*t(l)./2);
y21=exp(-i.*x(k)./(2*mu2)).*exp(i.*mu2.*t(l)./2);
a=[y11 y21; mu1.*x11 mu2.*x21];
b=[x11 x21; y11 y21];
q1(l,k)=q-(det(a)./det(b));
end
end
surf(x,t,abs(q1));
This is a plot of q1, where a and b are square matrices.
Now i write another solution i.e.
u1=-(det(c)./det(b));
where c=[x11 x21; mu2.*y11 mu1.*y21];
and plot a parametric curve between q1 and u1 (i.e. plot(q1,u1)). How can we do it by using loop? If we don't use loop then the dimension of the matrices does'nt match, i.e. one of the matrix would not be a square.
KSSV
2017년 5월 19일
Still, there is something missing....First change your above code following: Replace i with 1i, and preallocate q1.
q1 = zeros(length(x),length(t)) ;
Now coming to a,b,c which are
a=[X Y; -Y X];
b=[X Y; -conj(Y) conj(X)];
c=[X X; -Y Y];
You can make them a square matrix, using meshgrid to X,Y. But the determinants of them would be zero.
KSSV
2017년 5월 19일
clear all;
close all;
x=-10:.1:10;
t=-10:.1:10;
q=.2;
mu1=4-.3*1i;
mu2=.3+1i;
q1 = zeros(length(x),length(t)) ;
for k=1:length(x)
for l=1:length(t)
x11=exp(1i.*x(k)./(2*mu1)).*exp(-1i.*mu1.*t(l)./2);
x21=exp(1i.*x(k)./(2*mu2)).*exp(-1i.*mu2.*t(l)./2);
y11=exp(-1i.*x(k)./(2*mu1)).*exp(1i.*mu1.*t(l)./2);
y21=exp(-1i.*x(k)./(2*mu2)).*exp(1i.*mu2.*t(l)./2);
a=[y11 y21; mu1.*x11 mu2.*x21];
b=[x11 x21; y11 y21];
q1(l,k)=q-(det(a)./det(b));
end
end
surf(x,t,abs(q1));
Wajahat
2017년 5월 19일
KSSV, why we replace i with 1i, and preallocate q1. what is the reason behind it?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)