How to plot the following figure via matlab hist function?
Group 1: [10, 10, 20]; and Group 2: [15, 10, 8]. Each group consists of three algorithms' running times.
HIST is not a solution to your problem. Please try to look for the bar function
A sample snippet may look like
g1 = [10,10,20];
g2 = [15,10,8];
algStr = sprintfc('Algorithm %d',1:3);
bar(categorical({'Group1','Group2'}),[g1;g2])
legend(algStr)
You will also need to learn how to tweak the axes of the figure to match exactly to your sample graph. But I think I will leave it for you to find out.
It's not something you can do with the hist function, but something you can do with the bar function:
bar([10, 10, 20; 15, 10, 8])
Maple generates a strange solution form for this PDE. I am having hard time plotting the solution.
The solution is in terms of infinite series. I set the number of terms to say 20, and then set the time to plot the solution at t=2 seconds. Then want to plot the solution now for x=0..1. But the plot comes out empty.
When I sample the solution, and use listplot, I get correct solution plot.
Here is MWE
restart;
pde:=diff(u(x,t),t)=diff(u(x,t),x$2)+x;
bc:=u(0,t)=0,u(1,t)=0;
ic:=u(x,0)=x*(1-x);
sol:=pdsolve({pde,ic,bc},u(x,t)):
sol:=value(sol);
Now set the number of terms to 20 and set t=2
sol2:=subs(t=2,sol):
sol2:=subs(infinity=20,sol2);
The above is what I want to plot.
plot(rhs(sol2),x=0..1);
I get empty plot
So had to manually sample it and use listplot
f:=x->rhs(sol2);
data:=[seq([x,f(x)],x=0..1,.01)]:
plots:-listplot(data);
Solution looks correct, when I compare it to Mathematica's result. But Mathematica result is simpler as it does not have those integrals in the sum.
pde=D[u[x,t],t]==D[u[x,t],{x,2}]+x;
bc={u[0,t]==0,u[1,t]==0};
ic=u[x,0]==x(1-x);
DSolve[{pde,ic,bc},u[x,t],x,t];
%/.K[1]->n;
%/.Infinity->20;
%/.t->2;
And the plot is
Question is: How to plot Maple solution without manually sampling it?
Short answer seems to be that it is a regression in Maple 2017.3.
For me, your code works directly in Maple 2017.2 and Maple 2016.2 (without any unevaluated integrals). I will submit a bug report against the regression.
[edited] Let me know if any of these four ways work for your version (presumably Maple 2017.3).
restart;
pde:=diff(u(x,t),t)=diff(u(x,t),x$2)+x;
bc:=u(0,t)=0,u(1,t)=0;
ic:=u(x,0)=x*(1-x);
sol:=pdsolve({pde,ic,bc},u(x,t)):
sol:=value(sol);
sol5:=value(combine(subs([sum=Sum,t=2,infinity=20],sol))):
plot(rhs(sol5),x=0..1);
sol4:=combine(subs([sum=Sum,t=2,infinity=20],sol)):
(UseHardwareFloats,oldUHF):=false,UseHardwareFloats:
plot(rhs(sol4),x=0..1);
UseHardwareFloats:=oldUHF: # re-instate
sol2:=subs([sum=Sum,int=Int,t=2],sol):
# Switch integration and summation in second summand of rhs(sol).
sol3:=subsop(2=Sum(int(op([2,1,1],rhs(sol2)),op([2,2],rhs(sol2))),
op([2,1,2],rhs(sol2))),rhs(sol2)):
# Rename dummy index and combine summations.
sol3:=Sum(subs(n1=n,op([1,1],sol3))+op([2,1],sol3),
subs(n1=n,op([1,2],sol3))):
# Curtail to first 20 terms.
sol3:=lhs(sol2)=subs(infinity=20,simplify(sol3));
plot(rhs(sol3),x=0..1);
F:=unapply(subs([Sum='add'],rhs(sol3)),x):
plot(F,0..1);
[edited] Here is yet another way, working for me in Maple 2017.3 on 64bit Linux.
It produces the plot quickly, and doesn't involve curtailing any sum at 20 terms. Note that it does not do your earlier step of sol:=value(sol); since it does active int rather than Int before hitting any Sum with value. It also uses an assumption on x corresponding to the plotting range.
restart;
pde:=diff(u(x,t),t)=diff(u(x,t),x$2)+x:
bc:=u(0,t)=0,u(1,t)=0:
ic:=u(x,0)=x*(1-x):
sol:=pdsolve({pde,ic,bc},u(x,t)):
solA:=subs(sum=Sum,value(eval(eval(sol,t=2),Int=int))) assuming x>0, x<1;
plot(rhs(solA),x=0..1) assuming x>0, x<1;
I am trying to plot with Matlab. In particular, I try with numerous online source but none of them work.
Here is my problem, I am trying to plot the expression: y=2*(x-1)/(x-4)Kb/L, and I am interested in the range of x between 0 and 1.
K=40;
b=20;
L=0.5;
x=linspace(0,1,1000);
y=2*(x-1)/(x-4)*K*b/L;
but it returns:
y=275.01
I know linspace isn't the proper way to plot. How can I plot this function? I want to keep the K,b,L declaration because I might change them latter.
y=2*(x-1)./(x-4)*K*b/L; you should use ./ replace /
Like hzy199411 said, you should use the "." operation.
I would suggest that you type "help ." at a MATLAB command prompt. MATLAB will respond with a large index of results but look for the section on "Arithmetic Operators".
You may also try the command "doc arith" but I think the "help ." is more helpful because at least in MATLAB 2013 it verbosely lists more "dot" operators.
In short several arithmetic operators prefixed with '.' ("Dot") are "Element-by-Element" operations and as such they operate on each index of the array/matrix.
For example if you had an array s=1:20 and you performed the operation s/s you would get ans = 1, where as if you did s./s you would get an array of 1's with the same length as 's'.
I guess that you are a new matlab user :). The program is in general ok, but you should think of some things. First,
linspace is not a plotting function. The function is useful though. With your syntax it creates a vector of length 1000 with range [0,1]. For plotting, type:
plot(x,y);
Linecolor and style can be set as
plot(x,y,'r-.');
For predefined colors (here 'r-.' means a red dotted line). There are also some additional properties that can be found be checking the online help of plot.
Also as the others say, if you want to operate on each element in the vector, use ./. The / is a matrix operator.
Ta-Lib for Python - version:0.4.7.
Issue: Talib.MACD - Histo plotting line instead of histogram
Python 3.3.2
Matplotlib 1.2.1, Numpy 1.7.1!
OS: Windows 7
I am trying to add MACD, using Ta-lib. The histogram is plotting as Line instead of histogram. Need your guidance to sort it out.
(I tried to attach the image, but unable to do so due to lack of reputations.)
I am very much a fresher to programming and to Python as well as to other packages I am using. Your guidance will help me improve further.
My code:
Calculation:
macd = macd, macdsignal, macdhist = talib.MACD(r.close, 12, 26, 9)
Plotting:
ax1 = fig1.add_subplot(211, frameon=True)
macd = ax1.plot(macd, color='green')
macd = ax1.plot(macdsignal, color='red')
macd = ax1.plot(macdhist, color='blue')
Thanks in advance
Regards
Suresh
I'm not sure what Talib or MACD are, but I think you just need to replace your ax1.plot() with ax1.hist(macd, bins=50). There are a bunch of options but provided macd is just the set of data you want to bin and put into a histogram this should work.
The matplotlib documentation has enough to get you going an example:
http://matplotlib.org/api/pyplot_api.html#module-matplotlib.pyplot
you will need to Ctrl-f to find matplotlib.pyplot.hist.
If instead your macd is already binned then you may need to use ax1.bar() instead:
http://matplotlib.org/examples/api/barchart_demo.html
All are from this post.
What does these statement mean:
error(nargchk(5, 6, nargin));
plot(p(:,1), p(:,2), '.-'), axis equal
And what's this kinda syntax which I haven't quite often seen:
if nargin<6, steps = 36; end
I hope I don't come over as too unhelpful, but have you tried:
using Matlab's built-in help facilities to discover for yourself what the various statements mean ? or
running any of the code ?
All the statements are Matlab intrinsics and well documented. The use of , to separate statements on the same line is a bit unusual (I, for one, would usually put the statements on different lines in your examples), but not incorrect
Take a look at
help plot
help axis
help nargin