how to plot the graph for the functions 0<x<2 with y=sin x and y=x^3 and how to get point of intersection?

I will be thankful to your reply..

1 comentario

Replies are unlikely if you show no evidence of having attempted the homework or of having read the MATLAB documentation. If you've done minimal reading of the Getting Started material, you should be aware of the PLOT command and seen examples of its use.

Iniciar sesión para comentar.

Respuestas (3)

plot(). And fsolve()

1 comentario

x=linspace(0,2)
y1=cos(x)
y2=x.^2
plot(x,y1)
plot(x,y2)
grid on
i tried these but getting only one line so how will i get intersection point

Iniciar sesión para comentar.

x=linspace(0,2,1000);
y1=cos(x);
y2=x.^2;
plot(x,y1);
plot(x,y2);
grid on
I tried this but i need point of intersection of two curves so when i do this in matlab i get only one curve

10 comentarios

I tried your method now i get both the curves but no point of intersection as answer in matlab.
x=linspace(0,2,1000).';
y1=cos(x);
y2=x.^2;
plot([y1 y2]);
MATLAB is not going to tell you what the point of intersection is. You can zoom in near the point of intersection and use the datacursor to find nearby points. Or, without going to that trouble to find a guess, you can use fsolve() to determine where the point of intersection is.
x=linspace(0,2)
y1=cos(x)
y2=x.^2
[x',y1']
[x',y2']
plot(x,y1)
hold on
plot(x,y2)
fsolve(@(x)cos(x)-x.^2,1)
grid on
I used this is this correcet?Does the the graph show point of intersection.
If you want to mark or label the point of intersection on the graph, you will have to record the output of fsolve(), calculate the y corresponding to that x, and then create the form of mark that you want such as by using text() or annotate()
does the output of fsolve means the graph itself?I tried doing it but didnt get it.
x_of_intersection = fsolve(@(x)cos(x)-x.^2,1);
y_of_intersection = cos(x_of_intersection);
text(x_of_intersection, y_of_intersection, 'LOOK HERE')

Iniciar sesión para comentar.

Plot y x  sin over 0 2  x  with appropriate labels

Categorías

Etiquetas

Preguntada:

vb
el 2 de Dic. de 2012

Comentada:

el 13 de En. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by