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 Comment

Hi Nick
What version of MATLAB are you using?
With latest release your code works ok:

Sign in to comment.

Answers (2)

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 Comments

works! thank you
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

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.

Asked:

on 14 Jan 2018

Commented:

on 15 Jan 2018

Community Treasure Hunt

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

Start Hunting!