How can I graph arrays with negative exponentials? It keeps saying that there is an error but I can not figure out what is wrong

1 view (last 30 days)
%R/Dj%
x=[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2];
%Dj500%
f(x)=[6.02105exp(-6,) 1.514423exp(-3), 6.64exp(-3), 1.56exp(-2), 2.79exp(-2), 4.15exp(-2), 7.50exp(-2), 1.15exp(-01), 1.42exp(-1), 1.73exp(-1), 2.12exp(-1), 2.45exp(-1), 2.55exp(-1), 2.23exp(-1), 1.56exp(-1), 7.50exp(-2), 3.10exp(-2), 1.43exp(-2), 6.88exp(-3), 4.19exp(-3), 2.81exp(-3)];
%Dj1000%
g(x)=[4.46E-06 1.35E-03 5.96E-03 1.44E-02 0.025488866 4.07E-02 7.16E-02 1.12E-01 1.40E-01 1.69E-01 2.05E-01 2.42E-01 2.44E-01 2.06E-01 1.34E-01 4.06E-02 1.79E-02 6.49E-03 2.56E-03 1.46E-03 9.67E-04];
%Dj1500%
h(x)=[2.91E-06 1.21E-03 5.33E-03 1.30E-02 2.32E-02 3.95E-02 6.56E-02 0.106300452 1.34E-01 1.62E-01 1.98E-01 2.30E-01 2.33E-01 1.80E-01 9.14E-02 2.76E-02 1.08E-02 3.21E-03 1.10E-03 5.42E-04 3.89E-04];
plot(x,f(x),g(x),h(x))
xlabel('R/DJ')
ylabel('Ma/Mr')

Accepted Answer

Jon
Jon on 9 Aug 2019
Edited: Jon on 9 Aug 2019
You need to put a multiplication operator between the constants and the exponents
f(x)=[6.02105*exp(-6,) 1.514423*exp(-3), 6.64*exp(-3), ...
also the left hand side of your statement is not valid. You should just assign the result to a variable, for example
f=[6.02105*exp(-6,) 1.514423*exp(-3), 6.64*exp(-3), ...
You also have a number of other problems,
There are some stray commas,
f(x)=[6.02105*exp(-6,)
The length of your x vector must be the same as the length of the outputs that you are plotting against it (f,g,h) in your case x has 20 elements and f,g, and h have 21.
Once you get the lengths correct
In your call to plot, you must use something like
plot(x,f,x,g,x,h)
or combine f, x,and g into a matrix and just have one x variable, e.g.
plot(x,[f;g;h])
Given the number of errors you have it seems like you are still struggling with some of the basics of using MATLAB. I would highly recommend going through the onramp training if you have not already. It should only take a couple of hours and would be well worth it if you plan on using MATLAB for your work

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!