defining the range of an inverse function
1 view (last 30 days)
Show older comments
To plot function y1=3*exp(x./3+1); between x=[0:0.01:1]; using the hold on and axis equal add the inverse y2=3*log(x./3)-3; on the same graph between x values that come from the range of the original F(x) being x2=[3e^1/3:0.01:3e^4/3];, keep getting the error ;vectors must be same length, is there a better way I can define x2?
Thanks in advance for any assistance.
>> plot(x,y1)
>> hold on
>> axis equal
>> plot(x1,y2)
Error using plot
Vectors must be the same length.
0 Comments
Accepted Answer
Stephen23
on 18 Sep 2015
Edited: Stephen23
on 18 Sep 2015
MATLAB does not support implicit multiplication, which means you cannot write multiplication as 3e, you must write 3*e together with the multiplication symbol (although the letter e can be used for creating numbers using E-notation scientific numbers). And to get the value of Euler's number e you should use exp(1), as e is not defined with this value. So with these various changes we can define x2 as:
x2 = 3*exp(1)^1/3:0.01:3*exp(1)^4/3;
Which means the whole code now runs without error:
x1 = 0:0.01:1;
y1 = 3*exp(x1/3+1);
x2 = 3*exp(1)^1/3:0.01:3*exp(1)^4/3;
y2 = 3*log(x2/3)-3;
plot(x1,y1)
hold on
axis equal
plot(x2,y2)
Of course it is up to you to decide if the calculation itself is correct.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!