index exceeds matrix dimensions

I'm having an issue with the following code that models token ring behaviour:
clc
clear all
syms k C W
E(C) = ((50*2.15e-4)/(1-(50*k*2.215e-4)));
E(W) = (((2.637e-8)*(1-0.02215*k + (1.227e-4)*k^2) - (1.15e-4)*(1-0.011075*k))/ (0.0215*(1-0.02215*k + (1.227e-4)*k^2) - (((2.31125e-4)*k)*(1-0.011075*k))));
hold all
fplot(((50*2.15e-4)/(1-(50*k*2.215e-4))))
xlabel('lamda');
ylabel('E(C)');
title('Graph of E(C) against Lamda','FontSize',12);
when this program runs the error 'index exceeds matrix dimensions' appears and states a problem with the line beginning flpot. anyone know how to fix this?

1 Kommentar

John BG
John BG am 15 Jan. 2018
Hi Nick
What version of MATLAB are you using?
With latest release your code works ok:

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Star Strider
Star Strider am 14 Jan. 2018

0 Stimmen

The fplot function is expecting a function and a range for the independent variable.
Try this:
fplot(@(k) ((50*2.15e-4)./(1-(50*k*2.215e-4))), [-1 1])

2 Kommentare

Nick
Nick am 14 Jan. 2018
works! thank you
Star Strider
Star Strider am 14 Jan. 2018
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 14 Jan. 2018

0 Stimmen

The code runs to completion on newer versions of MATLAB. A couple of releases ago, fplot was improved to support symbolic expressions.
However, note that when you define
E(C) = expression1;
E(W) = expression2;
then you are overwriting E with the second statement. The statements are equivalent to
E = symfun(expression1, C);
E = symfun(expression2, W);
The syntax does not define two different functions, E subscript C and E subscript W.
Your fplot does not use either one at the moment though.

Gefragt:

am 14 Jan. 2018

Kommentiert:

am 15 Jan. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by