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?

 Réponse acceptée

Star Strider
Star Strider le 9 Avr 2017
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 commentaires

reem123
reem123 le 9 Avr 2017
Modifié(e) : reem123 le 9 Avr 2017
thank you soo much, but please I want just two dimensional graph Y vs x, with a=constant=0.02 really thank you and the graph like the one that is attached
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
reem123 le 10 Avr 2017
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
reem123 le 10 Avr 2017
like I need fitting or something else
reem123
reem123 le 10 Avr 2017
thank you for helping me, really thank you
Star Strider
Star Strider le 10 Avr 2017
My pleasure.
reem123
reem123 le 10 Avr 2017
Modifié(e) : Star Strider le 10 Avr 2017
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
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
reem123 le 10 Avr 2017
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
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
reem123 le 10 Avr 2017
very nice thank you sooo much
Star Strider
Star Strider le 10 Avr 2017
As always, my pleasure!
reem123
reem123 le 10 Avr 2017
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)
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])
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
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
reem123 le 10 Avr 2017
I will try to see it, really thank you for your help I taged you in another question..for theoretical and experimental values..
Star Strider
Star Strider le 10 Avr 2017
My pleasure.
I will look for the Question.
reem123
reem123 le 11 Avr 2017
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
Star Strider le 11 Avr 2017
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
reem123 le 11 Avr 2017
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
Star Strider le 11 Avr 2017
Please consult ‘Babar or Belle’ and find out what the ‘±’ values represent. See my previous Comment for details.
reem123
reem123 le 11 Avr 2017
Yes I am sorry, it is the standard deviation
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
reem123 le 12 Avr 2017
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
Star Strider le 12 Avr 2017
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.
reem123
reem123 le 12 Avr 2017
But I think that it must be like this
Star Strider
Star Strider le 12 Avr 2017
Please see the functions I referred you to.
I have no idea what you want to do.
reem123
reem123 le 12 Avr 2017
I will, Thank you
Star Strider
Star Strider le 12 Avr 2017
My pleasure.
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
Star Strider le 12 Avr 2017
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.
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'});
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
reem123 le 13 Avr 2017
Wow, very nice That is a lot kindness of you thank you
Star Strider
Star Strider le 13 Avr 2017
As always, my pleasure.
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])
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
Star Strider le 15 Avr 2017
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.
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
Star Strider le 16 Avr 2017
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.
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
Star Strider le 16 Avr 2017
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.
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
Star Strider le 16 Avr 2017
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
reem123 le 17 Avr 2017
Thank you.. No problem, I will use the vertical one.
Star Strider
Star Strider le 17 Avr 2017
That seems to be correct from your description of your problem.
reem123
reem123 le 17 Avr 2017
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
Star Strider le 17 Avr 2017
As always, my pleasure!
I always learn from Answering Questions, so we all benefit.
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
reem123 le 18 Avr 2017
Thank you I get it.. and this is my graph
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.
reem123
reem123 le 12 Juin 2017
oooh thank you Ihave to make plot
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by