Plotting graphs for scaling analysis
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello community
I am trying to plot the following functions on one graph (as an example):-
y1=-[(x+0.25)^0.5]/x
y2=0
y3=[(x-0.25)^0.5]/x
I expect to get a continuous graph. The values of x vary from -0.5 to 0.5. I am new to MATLAB so I would appreciate it if some explanation is provided.
clear all,
clc,
dell=0.5;
n=0.5;
x1= linspace(-0.5,0,100);
y1=-((x1+(dell/2)).^(1/n))/x1;
plot(x1,y1,'-o');
hold on;
x2=0;
y2=0;
plot(x2,y2,'-o');
x3= linspace(0.5,0,100);
y3=((x3-(dell/2)).^(1/n))/x3;
plot(x3,y3,'-o');
hold off;
Currently the graph comes out like this

I think the graph should be more like this

Many thanks and regards
Sushant
0 commentaires
Réponses (1)
Star Strider
le 25 Avr 2021
The most common problem I see here on Answers is forgetting to use element-wise division, so (./) instead of (/).
Making those two corrections in ‘y1’ and ‘y3’ —
dell=0.5;
n=0.5;
x1= linspace(-0.5,0,100);
y1=-((x1+(dell/2)).^(1/n))./x1;
plot(x1,y1,'-o');
hold on;
x2=0;
y2=0;
plot(x2,y2,'-o');
x3= linspace(0.5,0,100);
y3=((x3-(dell/2)).^(1/n))./x3;
plot(x3,y3,'-o');
hold off;
It may not be the plot you want (I’m not certain what is going on with that), however it’s likely closer.
0 commentaires
Voir également
Catégories
En savoir plus sur Spline Postprocessing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
