how can i plot a graph for y vs x?
10 次查看(过去 30 天)
显示 更早的评论
how can i plot a graph for y vs x, for this function a=-(0.1014758667.*sin (x))./(1+0.03063737048.*y.*cos(x)+0.002809.*y.^2) where a=0.5 and x=0:20:360, y=0:0.1:1?
采纳的回答
Star Strider
2017-4-9
Not possible.
The ‘a’ function has a maximum value of 0.1.
The Code —
x=0:20:360;
y=0:0.1:1;
[X,Y] = meshgrid(x,y);
a = @(x,y) (-0.1014758667.*sin(x))./(1+0.03063737048.*y.*cos(x)+0.002809.*y.^2);
A = a(X,Y);
[R,C] = find(A == 0.5)
figure(1)
meshc(X, Y, A)
54 个评论
Star Strider
2017-4-10
My pleasure.
This is easiest using data from the contour plot function, since it is easy to find (x,y) values at a specific value of ‘z’ with it.
One of these plots should do what you want:
x=0:20:360;
y=0:0.1:1;
[X,Y] = meshgrid(x,y);
a = @(x,y) (-0.1014758667.*sin(x))./(1+0.03063737048.*y.*cos(x)+0.002809.*y.^2);
A = a(X,Y);
figure(1)
hc = contour(X, Y, A, [0.02 0.02]);
title('Contour Plot (Contour = 0.02)')
grid
figure(2)
plot(hc(1,2:end), hc(2,2:end))
title('(X,Y) Plot — All Contour Data')
grid
figure(3)
plot(hc(1,(hc(1,2:end)<11),:), hc(2,(hc(1,2:end)<11),:))
title('(X,Y) Plot — Edited Contour Data')
grid
reem123
2017-4-10
thank you so much, but I am sorry the function is -0.1014758667.*y.*sin(x))./(1+0.03063737048.*y.*cos(x)+0.002809.*y.^2)=0.02 when I did the graph is not clear
reem123
2017-4-10
编辑:Star Strider
2017-4-10
I am sorry the function is
-0.1014758667.*y.*sin(x))./(1+0.03063737048.*y.*cos(x)+0.002809.*y.^2)=0.02
when I did the graph is not clear
Star Strider
2017-4-10
The corrected function helps significantly.
I believe I just saw the problem. Your ‘x’ variable (that you are using as arguments to your sin and cos functions) are in degrees (going from 0 to 360), while your function takes radian arguments. Changing sin to sind and cos to cosd (the ‘d’ indicates degrees) produces this plot:
x=linspace(0,360);
y=linspace(0,1);
[X,Y] = meshgrid(x,y);
a = @(x,y) (-0.1014758667.*y.*sind(x))./(1+0.03063737048.*y.*cosd(x)+0.002809.*y.^2);
A = a(X,Y);
figure(1)
hc = contour(X, Y, A, [0.02 0.02]);
title('Contour Plot (Contour = 0.02)')
grid
I believe that is what you want. It resembles some of the curves in your ‘matqq.jpg’ image.
The ‘hc’ matrix returned by the contour function are the ‘x’ (in ‘hc(1,2:end)’) and ‘y’ (in ‘hc(2,2:end)’) coordinates of the plotted curve.
reem123
2017-4-10
thank you so much, Yes I get it from your code.. my last question please that if I want to add another plot on the same graph with just changinging tha value of a..for example (a) was 0.02..I want to add also for a=0.04
Star Strider
2017-4-10
My pleasure.
To add a second contour at ‘a=0.04’, change the contour call to:
hc = contour(X, Y, A, [0.02 0.04]);
Recovering the (x,y) coordinates from ‘hc’ becomes a bit more complicated with this change. If you do not need them, you do not have to create ‘hc’. Simply do:
contour(X, Y, A, [0.02 0.04]);
reem123
2017-4-10
if I want to add another contour on the same graph but for another function for example b=-(0.1014758667.*cos (x))./(1+0.03063737048.*y.*cos(x)+0.002809.*y.^2)
Star Strider
2017-4-10
Use the hold function:
b = @(x,y) -(0.1014758667.*cosd(x))./(1+0.03063737048.*y.*cosd(x)+0.002809.*y.^2);
figure(1)
contour(X, Y, A, [0.02 0.04])
hold on
contour(X, Y, b(X,Y))
hold off
title('Contour Plot')
grid
You can set the specific contours on this one as well if you want:
contour(X, Y, b(X,Y), [0.02 0.04])
reem123
2017-4-10
yes very nice thank you I get what I want
x=linspace(0,360);
y=linspace(0,1);
[X,Y] = meshgrid(x,y);
a = @(x,y) (-0.1014758667.*y.*sind(x))./(1+0.03063737048.*y.*cosd(x)+0.002809.*y.^2);
A = a(X,Y);
b = @(x,y) (-0.03664+0.100285.*y.*cosd(x))./(1+0.03063737048.*y.*cosd(x)+0.002809.*y.^2);
figure(1)
contour(X, Y, A, [0.02 0.02])
hold on
contour(X, Y, b(X,Y), [-0.12 -0.12])
hold off
title('Contour Plot')
grid
>> x=linspace(0,360);
y=linspace(0,1);
[X,Y] = meshgrid(x,y);
a = @(x,y) (-0.1014758667.*y.*sind(x))./(1+0.03063737048.*y.*cosd(x)+0.002809.*y.^2);
A = a(X,Y);
b = @(x,y) (-0.03664+0.100285.*y.*cosd(x))./(1+0.03063737048.*y.*cosd(x)+0.002809.*y.^2);
figure(1)
contour(X, Y, A, [0.02 0.02])
hold on
contour(X, Y, b(X,Y), [-0.067 -0.067])
hold off
title('Contour Plot')
grid
Star Strider
2017-4-10
My pleasure.
I ran your code to get an idea of what you are doing. If you want to see everything about it in 3D, add this plot:
figure(9)
meshc(X, Y, A)
hold on
meshc(X, Y, b(X,Y))
hold off
grid on
view([-130 20])
reem123
2017-4-10
I will try to see it, really thank you for your help I taged you in another question..for theoretical and experimental values..
reem123
2017-4-11
I am sorry, but please if you can answer my question..... If my calculated value is 0.351, and the experimental value is 0.621+-0.4, if I want to make a plot to show that my calculated value is within 1 sigma or 2 sigma of the experimental one.
Star Strider
2017-4-11
What does ‘±0.4’ represent? How did you calculate it?
Is it a standard deviation, standard error, 95% confidence interval, or something else?
How many data points (observations) were used to calculate it? This is important, because the number of observations are used to calculate the standard error, and the degrees-of-freedom for the confidence interval based on the t-statistic.
reem123
2017-4-11
Ok, what I did is that I calculated the branching ratio for a particle in one method of calculations, and my result is 6.82*10-4, one of the experimental values that I take it from Babar or Belle is (5.8+-1.3)*10^-4....what is asked from me to do is to make a graph showing that my value is within this range(1segma)or(2segma) of the experimental one.
Star Strider
2017-4-11
Please consult ‘Babar or Belle’ and find out what the ‘±’ values represent. See my previous Comment for details.
Star Strider
2017-4-11
The standard deviation is ‘sigma’, so your calculation is straightforward.
For example,
sigma1 = 6.82E-4 - (5.8 + 1.3)*1E-4
sigma2 = 6.82E-4 - (5.8 + 2*1.3)*1E-4
sigma1 =
-2.8e-05
sigma2 =
-0.000158
Since it is negative in the first calculation, it is within 1*sigma. It will of course be less than 2*sigma, so I included that calculation as well, here as an example. Add or subtract the appropriate values of ‘sigma’ depending on whether your value is greater or less than the test value.
reem123
2017-4-12
Thank you so much..I know this and my supervisor said the same...but he asked me to do a graph showing this...as tha attached one..How I don't know..I think that this graph can be for (x,y) values..Thank you
Star Strider
2017-4-12
My pleasure.
I am not certain what you want. The Statistics and Machine Learning Toolbox tcdf or tpdf functions may work for you. You have to know the number of observations to use the t-statistics. If you don’t have them, or if you know there are more than about 30, you can use normcdf or normpdf. Also consider their inverses if you want to get the probabilities.
Star Strider
2017-4-12
Please see the functions I referred you to.
I have no idea what you want to do.
reem123
2017-4-12
I am sorry for my frequent questions... please see this code
h(1)= plot(1, 0.351, 'ko');
hold on;
h(2) = errorbar(1, 0.641, -0.4, 0.4, 'Marker', 'x');
h(3) = errorbar(1, 0.2, -0.1, 0.1, 'Marker', 'x');
axis([0.9 1.1 0 1.2]);
set(gca, 'XTick', []);
legend(h, {'Calculated', 'Experimental'});
I will do the same as the graph attached tt...but I want it on x axis..with different locations
Star Strider
2017-4-12
I don’t see the problem.
You can get the x and y values from the contour function as I previously demonstrated. Then plot them separately and plot your data and standard deviations with the errorbar function.
If you need the contour values at exactly the x values of the published data, use the interp1 function to find them.
reem123
2017-4-13
But I have a question please for more than one experimental data..I just add more values on code..but the problem that I want them on the graph separated from each other(different locations) on X axis...this is my code please
h(1)= plot(1, 0.351, 'ko');
hold on;
h(2) = errorbar(1, 0.641, -0.4, 0.4, 'Marker', 'x');
h(3) = errorbar(1, 0.2, -0.1, 0.1, 'Marker', 'x');
h(4) = errorbar(1, 0.3, -0.1, 0.1, 'Marker', 'x');
h(5) = errorbar(1, 0.5, -0.2, 0.2, 'Marker', 'x');
axis([0.9 1.1 0 1.2]);
set(gca, 'XTick', []);
legend(h, {'Calculated', 'Experimental'});
axis([0.9 1.1 0 1.2]);
set(gca, 'XTick', []);
legend(h, {'Calculated', 'Experimental'});
Star Strider
2017-4-13
You are plotting them all at ‘x=1’.
Try something like this:
x = 1 + [1 2 3 4]/50; % Use Correct ‘x’-Values
y = [0.641 0.2 0.3 0.5];
neg = [-0.4 -0.1 -0.1 -0.2];
pos = [0.4 0.1 0.1 0.2];
figure(1)
errorbar(x, y, neg, pos, 'x')
axis([0.9 1.1 0 1.2]) % Use Correct ‘axis’ Limits For ‘x’, ‘y’ & ‘error’ Ranges
Plot your data on the same plot using the hold function, and a second plot or scatter call.
reem123
2017-4-15
If I want to make the same graph with the same values, but the values are on x-axis and the lines are horizontally not vertically...thank you
x = 1 + [1 2 3 4]/50; % Use Correct ‘x’-Values
y = [0.641 0.2 0.3 0.5];
neg = [-0.4 -0.1 -0.1 -0.2];
pos = [0.4 0.1 0.1 0.2];
figure(1)
errorbar(x, y, neg, pos, 'x')
axis([0.9 1.1 0 1.2])
reem123
2017-4-15
another question please..If I have an experimental value of < 3.6 with 90% Confedence Level...what does that mean? and can I add this experimental value to the same graph..with this code
x = 1 + [1 2 3 4]/50; % Use Correct ‘x’-Values
y = [0.641 0.2 0.3 0.5];
neg = [-0.4 -0.1 -0.1 -0.2];
pos = [0.4 0.1 0.1 0.2];
figure(1)
errorbar(x, y, neg, pos, 'x')
axis([0.9 1.1 0 1.2])
Star Strider
2017-4-15
The confidence limits are the probability (in this example) that the true value of the measured quantity is within those limits.
Measured quantities always have some amount of error, because the system creating the measurement may be contaminated by noise, the measuring equipment may have noise in the ‘front-end’ analogue amplifiers, and there is quantization error in the approximation of the analogue-to-digital converter. There may be other sources as well.
All the noise is modeled as being normally distributed, although some sources may have other distributions. For example quantization noise is uniformly distributed.
The t-distribution is a variation of the normal distribution, and incorporates a ‘correction’ of sorts to increase the width of the confidence interval to account for a small sample size. The t-distribution approximates the normal distribution with a sample size greater than about 30, so you can use the normal distribution with larger sample sizes without significant loss of accuracy.
This is a qualitative discussion rather than a rigorous one. For details, see any standard textbook on statistics.
The errorbar function will accept and plot whatever quantities you give it. It will plot standard deviations, standard errors, confidence limits, and anything else you want. You simply have to be certain that the calculations creating those values are correct.
reem123
2017-4-16
Ok, thank you I have two questions please: 1- If I want to make the same graph with the same values, but the values are on x-axis and the lines are horizontally not vertically 2- can can I add this experimental value ( < 3.6 with 90%CL) to the same graph
x = 1 + [1 2 3 4]/50; % Use Correct ‘x’-Values
y = [0.641 0.2 0.3 0.5];
neg = [-0.4 -0.1 -0.1 -0.2];
pos = [0.4 0.1 0.1 0.2];
figure(1)
errorbar(x, y, neg, pos, 'x')
axis([0.9 1.1 0 1.2])
Star Strider
2017-4-16
If you want to plot the error bars horizontally, use the 'horizontal' argument with the errorbar function (in R2017a and other recent releases).
See the documentation on the errorbar function for details.
reem123
2017-4-16
I did like this, but not working
x = 1 + [1 2 3 4]/50;
y = [0.641 0.2 0.3 0.5];
err = [0.4 0.1 0.1 0.2];
figure(1)
errorbar(x,y,err,'horizontal')
axis([0.9 1.1 0 1.2]
Star Strider
2017-4-16
It works correctly for me (in R2017a).
I suspect the problem is with the x-axis in your plot. I guessed at the x-coordinates to illustrate the correct way to use the plot and errorbar functions.
You must define the correct x-coordinates for your data.
reem123
2017-4-16
I will try..this my code with the error
x = [0.641 0.2 0.3 0.5];
y = [1 2 3 4];
err = [0.4 0.1 0.1 0.2];
figure(1)
errorbar(x,y,err,'horizontal')
Error using errorbar (line 45)
Error in color/linetype argument.
Star Strider
2017-4-16
I do not know the version of MATLAB you are using. (I am using R2017a.)
There are File Exchange functions that will allow you to plot horizontal error bars. However, I do not know if they work for MATLAB versions R2014b and later, when handle graphics version 2, known as ‘HG2’, was introduced.
reem123
2017-4-17
Thank you so much for your help..even though you don't know me,you helped me a lot, you made be like MATLAB and like to learn it well. My Best Regards to you
Star Strider
2017-4-17
As always, my pleasure!
I always learn from Answering Questions, so we all benefit.
reem123
2017-4-18
Thank you.. I wrote this code I want to draw a with b, for different values of x and y..when x=260 then y=0.15..(260,0.15) when x=200 then y=0.1..(200,0.1) and etc.
x=260, 200, 320, 230, 216, 190, 302;
y=0.15, 0.1, 0.25, 0.2, 0.34, 0.35, 1.08;
a =(-0.1014758667.*y.*sind(x))./(1+0.03063737048.*y.*cosd(x)+0.002809.*y.^2);
b =(-0.03664+0.100285.*y.*cosd(x))./(1+0.03063737048.*y.*cosd(x)+0.002809.*y.^2);
plot (a,b,'*r');
reem123
2017-6-12
Dear Star Strider ..please I have a question ..I wrote this one ..I want to graph br Vs. x
x=5.36653:0.00001:5.36701;
z=(x.^2/6.9938)-1;
w=x/1.87;
r=log((w+(w.^2-1).^0.5)./(w.^2-1).^0.5);
e=((2.*0.4202)./(1+w))+0.4202.*r;
br=((((3.209*10.^-11).*(z+w).^2).*((0.0089888512.*e).^2).*((x.^4)-13.9876.*(x.^2)).^0.5)./(2.078813*10.^-22).*(x.^2)).*1.512.*10.^-12;
figure(x,br);
Error using figure
Too many input arguments.
Star Strider
2017-6-12
Change your figure call to a figure and plot call:
figure
plot(x,br)
That worked when I ran it with the rest of your code, and produced an acceptable plot.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
标签
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 (한국어)