Plotting graphs for scaling analysis

조회 수: 7 (최근 30일)
Sushant Singh
Sushant Singh 2021년 4월 25일
답변: Star Strider 2021년 4월 25일
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