이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
plot system in 3-D
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi
I need to plot in 3-D ,the first equation ,and the second equation, then the third equation
after that plot all in one drawing
if any prof. can help me....thanks a lots....
there is my equations:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/544026/image.png)
And this is my matlab :
N = 1000;
Q1 = rand(10,N);
Q=reshape(Q1,1,[]); % convert matrix to row vector
sum1=0;sum2=0;sum3=0;sum4=0;sum5=0;sum6=0;
for j=1:10000
sum1=sum1+1/(A+(G*B*((Q(j))^(G-1))));
sum2=sum2+(Q(j));
sum3=sum3+(G*((Q(j))^(G-1)))/(A+(G*B*((Q(j))^(G-1))));
sum4=sum4+(Q(j))^(G);
sum5=sum5+(((G*log(Q(j)))*((Q(j))^(G-1)))+((Q(j))^(G-1)))/(A+(B*G*((Q(j))^(G-1))));
sum6=sum6+((Q(j))^(G))*log(Q(j));
end
f(A,B,G)=sum1-sum2;
g(A,B,G)=sum3-sum4;
h(A,B,G)=B*sum5-B*sum6;
plot3d(f(A,B,G)=0,color=red);
plot3d(g(A,B,G)=0,color=yellow);
plot3d(h(A,B,G)=0,color=blue);
display({plotf,plotg,ploth},axes= );
my variable : A,B,G in matlab ...INSTEAD OF x, y, z for the 3-D
what I add to this program to plot all the three eqations, in different colors please, and then put them in one drawing .
I write
plot ( .,)
but I dont know what write between the Parentheses.
댓글 수: 3
Walter Roberson
2021년 3월 9일
plot3d(f(A,B,G)=0,color=red);
It looks to me as if you wrote your original code in Maple rather than in MATLAB ?
hasan s
2021년 3월 9일
I searched a lot and could not find a way to write it in Matlab, and find this in Maple
I thought the same way .
I hope to help me write it in matlab
These are the same equations for the program that you helped me with while you are the person he knows best
I really appreciate your time
If you can help me, thanks a lot
채택된 답변
Walter Roberson
2021년 3월 10일
digits(16);
syms A B G
N = 1000;
Q1 = rand(10,N);
Q = vpa(reshape(Q1,1,[])); % convert matrix to row vector
sum1=0;sum2=0;sum3=0;sum4=0;sum5=0;sum6=0;
for j=1:10000
sum1=sum1+1/(A+(G*B*((Q(j))^(G-1))));
sum2=sum2+(Q(j));
sum3=sum3+(G*((Q(j))^(G-1)))/(A+(G*B*((Q(j))^(G-1))));
sum4=sum4+(Q(j))^(G);
sum5=sum5+(((G*log(Q(j)))*((Q(j))^(G-1)))+((Q(j))^(G-1)))/(A+(B*G*((Q(j))^(G-1))));
sum6=sum6+((Q(j))^(G))*log(Q(j));
end
sum1m2 = vpa(sum1 - sum2);
sum3m4 = vpa(sum3 - sum4);
sum5m6 = vpa(B*sum5-B*sum6);
f = matlabFunction(sum1m2, 'vars', [A, B, G]); %really long
g = matlabFunction(sum3m4, 'vars', [A, B, G]); %really long
h = matlabFunction(sum5m6, 'vars', [A, B, G]); %really long
fimplicit3(f, 'r');
drawnow();
hold on
fimplicit3(g, 'y');
drawnow();
fimplicit3(h, 'b');
However, that fimplicit3 of h takes at least an hour! And the g is in the same place as f it looks like!
댓글 수: 25
Walter Roberson
2021년 3월 10일
You can get a fairly different view with this, but be warned that computation will take about half an hour.
digits(16);
syms A B G
N = 1000;
Q1 = rand(10,N);
Q = vpa(reshape(Q1,1,[])); % convert matrix to row vector
sum1=0;sum2=0;sum3=0;sum4=0;sum5=0;sum6=0;
for j=1:10000
sum1=sum1+1/(A+(G*B*((Q(j))^(G-1))));
sum2=sum2+(Q(j));
sum3=sum3+(G*((Q(j))^(G-1)))/(A+(G*B*((Q(j))^(G-1))));
sum4=sum4+(Q(j))^(G);
sum5=sum5+(((G*log(Q(j)))*((Q(j))^(G-1)))+((Q(j))^(G-1)))/(A+(B*G*((Q(j))^(G-1))));
sum6=sum6+((Q(j))^(G))*log(Q(j));
end
sum1m2 = vpa(sum1 - sum2);
sum3m4 = vpa(sum3 - sum4);
sum5m6 = vpa(B*sum5-B*sum6);
f = matlabFunction(sum1m2, 'vars', [A, B, G]); %really long
g = matlabFunction(sum3m4, 'vars', [A, B, G]); %really long
h = matlabFunction(sum5m6, 'vars', [A, B, G]); %really long
[Ag, Bg, Gg] = meshgrid(linspace(-5,5)); %do not use ndgrid
Fgrid = f(Ag,Bg,Gg); %several minutes
Ggrid = g(Ag,Bg,Gg); %about 10 minutes!
Hgrid = h(Ag,Bg,Gg); %about 15 minutes!
p(1) = patch(isosurface(Ag, Bg, Gg, Fgrid, 0), 'facecolor',[0.6 0 0], 'edgecolor','none','FaceAlpha', 0.5);
p(2) = patch(isosurface(Ag, Bg, Gg, Ggrid, 0), 'facecolor',[0 0.6 0], 'edgecolor','none','FaceAlpha', 0.5);
p(3) = patch(isosurface(Ag, Bg, Gg, Hgrid, 0), 'facecolor',[0 0 0.6], 'edgecolor','none','FaceAlpha', 0.5);
hasan s
2021년 3월 10일
편집: hasan s
2021년 3월 10일
Thank you very much prof. Walter
Your programming is excellent and the graphic is good .. I expected it to be in a specific, but random appearance. I need the positive coordinates what I change please?
In the case of 9 different equations, do they follow the same programming in the drawing ??
Because I am required to draw from 3 to 9 equations like this
Walter Roberson
2021년 3월 10일
The 0.6 are color components.
linspace is fine with 0.1,4.9
isosurface accepts 3d grids of coordinates and a 3d grid of result values, and it effectively creates a 3d contour of the locations that match the last value (0 in this case), so it is drawing surfaces around all the places with value 0.
hasan s
2021년 3월 10일
pardon .. what mean 0.6 are color components? is there are any number else.
in case of 9 equations is [0.6 0 0] become
[0.6 0 0 0 0 0 0 0 0]
[0 0.6 0 0 0 0 0 0 0]
and so on
?? or not
I want to try please,because I am required to draw from 3 to 9 equations like this
Walter Roberson
2021년 3월 10일
There are three color components, Red, Green, and Blue. You can use any sets of colors you want. I will post an update in a few minutes.
Walter Roberson
2021년 3월 10일
On my system the below takes under 13 minutes. You can increase the resolution (which would make it slower) by increasing NumPoints.
As you add more equations, add their evaluated values to the grids cell array, and add legend labels for them to the gridnames variable.
NumPoints = 50;
tic
digits(16);
syms A B G
N = 1000;
Q1 = rand(10,N);
Q = vpa(reshape(Q1,1,[])); % convert matrix to row vector
sum1=0;sum2=0;sum3=0;sum4=0;sum5=0;sum6=0;
for j=1:10000
sum1=sum1+1/(A+(G*B*((Q(j))^(G-1))));
sum2=sum2+(Q(j));
sum3=sum3+(G*((Q(j))^(G-1)))/(A+(G*B*((Q(j))^(G-1))));
sum4=sum4+(Q(j))^(G);
sum5=sum5+(((G*log(Q(j)))*((Q(j))^(G-1)))+((Q(j))^(G-1)))/(A+(B*G*((Q(j))^(G-1))));
sum6=sum6+((Q(j))^(G))*log(Q(j));
end
sum1m2 = vpa(sum1 - sum2);
sum3m4 = vpa(sum3 - sum4);
sum5m6 = vpa(B*sum5-B*sum6);
f = matlabFunction(sum1m2, 'vars', [A, B, G]); %really long
g = matlabFunction(sum3m4, 'vars', [A, B, G]); %really long
h = matlabFunction(sum5m6, 'vars', [A, B, G]); %really long
[Ag, Bg, Gg] = meshgrid(linspace(0.1, 4.9,NumPoints));
Fgrid = f(Ag,Bg,Gg);
Ggrid = g(Ag,Bg,Gg);
Hgrid = h(Ag,Bg,Gg);
grids = {Fgrid, Ggrid, Hgrid};
gridnames = {'f', 'g', 'h'};
ngrid = length(grids);
cmap = parula(ngrid);
patches = gobjects(1,ngrid);
view(3);
for K = 1 : ngrid
patches(K) = patch(isosurface(Ag, Bg, Gg, grids{K}, 0), 'facecolor', cmap(K,:), 'edgecolor','none','FaceAlpha', 0.5, 'displayname', gridnames{K});
end
legend show
toc
beep
Walter Roberson
2021년 3월 10일
You should probably add xlabel(), ylabel(), zlabel() calls to the code.
hasan s
2021년 3월 10일
PLEASE YOU SAY "You should probably add xlabel(), ylabel(), zlabel() calls to the code"
Where add it ? in the program?
hasan s
2021년 3월 10일
편집: hasan s
2021년 3월 10일
I will try for 4 to 9 equations.thanks alot Porf. Walter for your help
Colors became many in the drawing
How can I recognize the points of intersection at the main colars only of 3(or 9 ) equations?
Can you advise me?
or add something in the program?to know the intersection points of these 3(or 9) equations
Walter Roberson
2021년 3월 10일
Put the xlabel(), ylabel(), zlabel() calls after the "legend show" call.
Walter Roberson
2021년 3월 10일
Here is a modified version that is "ready" to work towards intersection.
NumPoints = 50;
tic
digits(16);
syms A B G
N = 1000;
Q1 = rand(10,N);
Q = vpa(reshape(Q1,1,[])); % convert matrix to row vector
sum1=0;sum2=0;sum3=0;sum4=0;sum5=0;sum6=0;
for j=1:10000
sum1=sum1+1/(A+(G*B*((Q(j))^(G-1))));
sum2=sum2+(Q(j));
sum3=sum3+(G*((Q(j))^(G-1)))/(A+(G*B*((Q(j))^(G-1))));
sum4=sum4+(Q(j))^(G);
sum5=sum5+(((G*log(Q(j)))*((Q(j))^(G-1)))+((Q(j))^(G-1)))/(A+(B*G*((Q(j))^(G-1))));
sum6=sum6+((Q(j))^(G))*log(Q(j));
end
sum1m2 = vpa(sum1 - sum2);
sum3m4 = vpa(sum3 - sum4);
sum5m6 = vpa(B*sum5-B*sum6);
f = matlabFunction(sum1m2, 'vars', [A, B, G]); %really long
g = matlabFunction(sum3m4, 'vars', [A, B, G]); %really long
h = matlabFunction(sum5m6, 'vars', [A, B, G]); %really long
[Ag, Bg, Gg] = meshgrid(linspace(0.1, 4.9,NumPoints));
Fgrid = f(Ag,Bg,Gg); %several minutes
Ggrid = g(Ag,Bg,Gg); %about 10 minutes!
Hgrid = h(Ag,Bg,Gg); %about 15 minutes!
grids = {Fgrid, Ggrid, Hgrid};
gridnames = {'f', 'g', 'h'};
ngrid = length(grids);
cmap = parula(ngrid);
view(3);
patches = gobjects(1,ngrid);
surfaces = cell(ngrid, 1);
for K = 1 : ngrid
surfaces{K} = isosurface(Ag, Bg, Gg, grids{K}, 0);
patches(K) = patch(surfaces{K}, 'facecolor', cmap(K,:), 'edgecolor','none','FaceAlpha', 0.5, 'displayname', gridnames{K});
end
xlabel('A');
ylabel('B');
zlabel('G');
legend show
toc
beep
Walter Roberson
2021년 3월 11일
The code was modified so that the objects returned by isosurface() are explicitly saved. Those are struct() with Faces and Vertices information about the polyhedra created.
I am not finding direct code to compute the intersection of polyhedra of these types. I do see
https://www.mathworks.com/matlabcentral/fileexchange/30892-analyze-n-dimensional-polyhedra-in-terms-of-vertices-or-in-equalities from @Matt J
which accepts lists of vertices, but does not accept face information. To use that routine, you would need to first break out the information returned by isosurface() into disjoint cycles at the very least, asking about the intersection of each member of one set with each member of the other set. However, the polyhedra returned by isosurface are by no means guaranteed to be convex, and if you just submit the vertices without the face information you can get distorted ideas of where the intersections are.
I tagged Matt; if he happens to notice, then perhaps he will have some ideas.
hasan s
2021년 3월 13일
편집: Walter Roberson
2021년 3월 13일
please prof. Walter , if you can :
I am trying to drawing 4 equations containing sums , I write the sums , but I donot know which of these sums is true ,since it is difficult equations.... this one:
for j=1:10000
sum1=sum1+((log((Q(j))/(A)))^2)*(((Q(j))/(A))^(2*(C)))*exp(2*(((Q(j))/(A))^(C)));
sum2=sum2+exp(2*(B)*(1-exp(((Q(j))/(A))^(C))))*exp(2*(((Q(j))/(A))^(C)))*(((Q(j))/(A))^(2*(C)))*(log((Q(j))/(A))^2);
end
where, exp(2*(B)*(1-exp(((Q(j))/(A))^(C)))) ,is very long.
or I must separate these functions like this:
for j=1:10000
m(j)=((Q(j))/(A)))
n(j)=log(m(j))
v(j)=(((Q(j))/(A))^(2*(C)))
z(j)=2*(((Q(j))/(A))^(C))
x(j)=exp(z(j))
sum1=sum1+((n(j))^2)*v(j)*x(j)
w(j)=((Q(j))/(A))^(C)
d(j)=exp(w(j))
q(j)=((Q(j))/(A))^2
l(j)=log(q(j))
sum2=sum2+exp(2*(B)*(1-d(j)))*(x(j))*(v(j))*(l(j))
end
which one is right ,please??
Walter Roberson
2021년 3월 13일
sum1 is the same for both of them.
sum2 is different between the two of them.
I do not know which one is "right" as you have not indicated which equation sum2 corresponds to.
hasan s
2021년 3월 13일
thanks alot for your reply
Yes,,,you are right. I should print the equations.
both of them is same ..but
I donot know how to write difficult functions
The first write ....I wrote it in its full form, and I noticed that the long function was not calculated by the program like
exp( 2*(B)*(1-exp(((Q(j))/(A))^(C))) ) ,is very long
the output still as exp(..)
The second write....I divided it up and then collected in the second writing. Is that permissible ??
But when I write seprate the functions, a warning appears to me for its writing .like those
m(j)=((Q(j))/(A)))
n(j)=log(m(j))
v(j)=(((Q(j))/(A))^(2*(C)))
z(j)=2*(((Q(j))/(A))^(C))
x(j)=exp(z(j))
w(j)=((Q(j))/(A))^(C)
d(j)=exp(w(j))
q(j)=((Q(j))/(A))^2
l(j)=log(q(j))
hasan s
2021년 3월 13일
thanks alot for your note, I donot understand these numbers and how you get it , ...I change it.
like this sum... how can I write these sum in matlab , please
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/548433/image.png)
I write it as follows:
for j=1:10000
m(j)=(Q(j)/A);
n(j)=log(m(j));
v(j)=((Q(j)/A)^(2*C));
z(j)=2*((Q(j)/A)^(C));
x(j)=exp(z(j));
sum1=sum1+((n(j))^2)*v(j)*x(j);
w(j)=(Q(j)/A)^(C);
d(j)=exp(w(j));
q(j)=(A/(Q(j)))^2;
l(j)=log(q(j));
sum2=sum2+exp(2*(B)*(1-d(j)))*x(j)*v(j)*(l(j))^2;
sum3=....
end
is right ???please..
I have line warining in m "the variable m appears to change size on every loop iteration"
also , for n,v,z,x,w,d,q,l the same line warining.
thank you very much prof. Walter for your help
Walter Roberson
2021년 3월 13일
maxj = 10000;
m = zeros(1,maxj);
n = zeros(1,maxj);
v = zeros(1,maxj);
z = zeros(1,maxj);
x = zeros(1,maxj);
w = zeros(1,maxj);
d = zeros(1,maxj);
q = zeros(1,maxj);
l = zeros(1,maxj);
for j=1:maxj
m(j)=(Q(j)/A);
n(j)=log(m(j));
v(j)=((Q(j)/A)^(2*C));
z(j)=2*((Q(j)/A)^(C));
x(j)=exp(z(j));
sum1=sum1+((n(j))^2)*v(j)*x(j);
w(j)=(Q(j)/A)^(C);
d(j)=exp(w(j));
q(j)=(A/(Q(j)))^2;
l(j)=log(q(j));
sum2=sum2+exp(2*(B)*(1-d(j)))*x(j)*v(j)*(l(j))^2;
sum3=....
end
I did not attempt to verify the equations yet: I am just showing here how to get rid of the warning.
hasan s
2021년 3월 21일
편집: Walter Roberson
2021년 3월 21일
please prof. Walter , when you can...
Is there a similar formula to "zeros(1,maxj);"
To get rid of the warning؟؟
if the warning remains ... is this thing that may make these results that obtained scientifically incorrect??
Walter Roberson
2021년 3월 21일
Sorry, I do not have the resources to assist you further for the next while.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
태그
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 (한국어)