
Error on Matlab grading system - Variable y has an incorrect value.
20 次查看(过去 30 天)
显示 更早的评论
For a MATLAB course, I have to program a code to compute the voltage at three junctions of an electrical system such as the one depicted below:

Following Kirchhoff's First Law, I have designed the following code:
function volt = voltage(V, R)
a = [(R(7)*R(2)+R(1)*R(7)+R(1)*R(2)), -R(1)*R(2), 0; (R(3)*R(8)*R(4)), (R(7)*R(8)*R(4)-R(3)*R(8)*R(4)-R(3)*R(7)*R(4)+R(3)*R(7)*R(8)), (R(3)*R(7)*R(4)); 0, (R(5)*R(6)), (R(8)*R(6)+R(5)*R(8)-R(5)*R(6))]; %3x3 matrix containing the value oh the resistance at each junction as functions of A, B and C
b = V*[(R(7)*R(2)); (R(7)*R(8)*R(4)); (R(8)*R(6))]; %1x3 matrix, product of solving Kirchhoff's firs law for each junction
volt = a\b;
end
When I run it on MATLAB, it works. When I run it on the platform, it works too. But when I try to submit my assignement, the following error appears:
Variable y has an incorrect value. Input was V = 10 and R = [1,2,4,5,13,4,8,1]

What am I doing wrong?
2 个评论
Cris LaPierre
2022-1-6
编辑:Cris LaPierre
2022-1-8
EDIT: Moving OP's comment here
I mean that it worked on my installed version of MATLAB, i.e. that I indroduced some V and R values and I obtained the expected voltage on A, B and C. I attach an image of the question, so you can see how did I obtain those matrixes:

So, when I said that it worked, I meant that I introduce those suggested R values at the end, and I obtanied the desired voltages, both on my installed MATLAB version and on the grading system, but then the errro appeared...
Thanks for replying!
采纳的回答
Cris LaPierre
2022-1-6
I took a new look and decided to back out your equations to see what is happening. My best guess is that you are inconsistent in defining your current directions.
My recommendation is to draw the current direction through each resistor, and then write your equations assuming that direction.
For example, for node A, the current through R7 is defined as leaving A and going into B:

However, in backing out your equation for node B, you define the current as heading from B to A by doing one of the following:


Put another way, write an equation for each resistor current, and then use that same equation everywhere. So here, that means for R7, my equation defines the current direction as going from A to B: 

That means for node A, the current is leaving A, so subtract this equation: 

It also means that for node B, the current is enterring B, so add this equation: 

2 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!