plotting as a function of x

5 次查看(过去 30 天)
Ibraheem
Ibraheem 2022-10-29
I have no problem ploting as a function of y but when i try replicating it and plotting it as a function of x i get an error or the image comes out wrong.
In this case i want to plot x = y.^1/3 (y=x^3) as a function of x bounded by x=1 , y = 1 and y=0
i used this code when doing it as a function of y
f = @(x) x.^3;
g = @(x) x-x;
fplot(f, [-3, 3]), hold on
fplot(g, [-3, 3], 'LineWidth',2)
x1 = 0;
x3 = 1;
xcoord = linspace(x1, x3, 100);
ycoord = [f(xcoord); g(xcoord)];
plot([xcoord;xcoord], ycoord),
plot(xline(1))
hold off
But i can't seem to replicate it using a function of x.
Thanks

回答(1 个)

Walter Roberson
Walter Roberson 2022-10-29
x = y.^1/3
MATLAB would parse that as being x = (y.^1)/3 which is x = y/3 which is not what you want.
If you were to use x = y.^(1/3) then that would be closer. However, you would encounter the problem that P.^Q is defined as being equivalent to exp(Q*log(P)) -- and log() of a negative number is complex, so if the power Q is not an even integer, the result is going to be complex.
To solve the problem you are going to need to use nthroot such as x = nthroot(y, 3)

类别

Help CenterFile Exchange 中查找有关 Debugging and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by