Plotting graphs for scaling analysis

8 次查看(过去 30 天)
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

回答(1 个)

Star Strider
Star Strider 2021-4-25
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.

类别

Help CenterFile Exchange 中查找有关 Spline Postprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by