You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
plot system in 3-D
1 view (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 9 Mar 2021
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
on 9 Mar 2021
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
Accepted Answer
Walter Roberson
on 10 Mar 2021
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 Comments
Walter Roberson
on 10 Mar 2021
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
on 10 Mar 2021
Edited: hasan s
on 10 Mar 2021
thanks a lot prof. Walter
I try now to run it .
please what mean :
linspace(-5,5)? I want to plot in positive coordinates. can I put as (0.1,4.9),or only integer
[0.6 0 0]? what mean 0.6 in different place
(Ag, Bg, Gg, Fgrid, 0)? is 0 mean f(A,B,G)=0
hasan s
on 10 Mar 2021
Edited: hasan s
on 10 Mar 2021
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
on 10 Mar 2021
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
on 10 Mar 2021
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
on 10 Mar 2021
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
on 10 Mar 2021
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
on 10 Mar 2021
You should probably add xlabel(), ylabel(), zlabel() calls to the code.
hasan s
on 10 Mar 2021
Edited: hasan s
on 10 Mar 2021
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
on 10 Mar 2021
Put the xlabel(), ylabel(), zlabel() calls after the "legend show" call.
Walter Roberson
on 10 Mar 2021
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
on 11 Mar 2021
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
on 13 Mar 2021
Edited: Walter Roberson
on 13 Mar 2021
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
on 13 Mar 2021
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
on 13 Mar 2021
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))
Walter Roberson
on 13 Mar 2021
m(j)=((Q(j))/(A)))
1 0 12 3 21 2 10!
You have too many close brackets
hasan s
on 13 Mar 2021
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
on 13 Mar 2021
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
on 21 Mar 2021
Edited: Walter Roberson
on 21 Mar 2021
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
on 21 Mar 2021
Sorry, I do not have the resources to assist you further for the next while.
More Answers (0)
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)