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

John BG
John BG 2018년 1월 15일
Hi Nick
What version of MATLAB are you using?
With latest release your code works ok:

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2018년 1월 14일

0 개 추천

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

Nick
Nick 2018년 1월 14일
works! thank you
Star Strider
Star Strider 2018년 1월 14일
My pleasure!
If my Answer helped you solve your problem, please Accept it!

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2018년 1월 14일

0 개 추천

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.

질문:

2018년 1월 14일

댓글:

2018년 1월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by