a) Write a script which uses for loops to calculate the resistance of the copper wire at the five lengths. Display the results in two columns, one for the length and one for the resistance
b) Write additional script which uses vectorisation to calculate the resistance of the copper wire at the five lengths

댓글 수: 4

Adam
Adam 2014년 10월 23일
This is Matlab Answers, not the pose a random challenge forum! Why are you telling us to write a script? Most of us are not interested in the resistance of copper wire.
If you have an actual Matlab question something like "I've tried to do this in this way, but this part of it doesn't quite work correctly for this reason..." you will likely get some help here.
Charrizard harrizard
Charrizard harrizard 2014년 10월 23일
Sorry I've gotten the vectorisation down I just don't see how fprintf or for loops come into the problem,
resistivity = 1.68*(10.^-8);
length = 2; diameter = 0.001;
area = (pi*(diameter.^2));
disp('Area')
disp(area)
disp('Percentage elongation = pe')
pe = [ 0 3 6 9 12 ]
postlength =((pe+100)/100)*length;
disp('Lengths of copper wire after elongation')
disp(postlength)
disp('resistance at 5 wire lengths')
R = resistivity*postlength/area;
disp ( R )
That is basically what I've got so far
Patrik Ek
Patrik Ek 2014년 10월 23일
편집: Patrik Ek 2014년 10월 23일
I am not sure about part b, but for part a: Assuming that you have a inhomogeneous leader of some length and with some width that depend on x and y. Also assuming that you have a measured voltage from end to end and also have a measured magnetic field at a radius r from the center. The answer would be far too long to write here, but as a hint you use Amperes law to calculate the current. And to Charrizard harrizard: you have assumed that there is a homogeneous wire and DC. It is extremly likely that the wire is homogeneous in both width and materialbut it is not given :). However, the frequency should be given to make an appropriate estimation.

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

 채택된 답변

Adam
Adam 2014년 10월 23일

0 개 추천

Well, if you went straight to the vectorisation solution it is a bit silly to also require a for loop solution, but I guess if those are the questions you have to answer you have to do the reverse of what is usually done and instead of operating on your vector of values all at once just put in a loop from 1 upto the length of the vector (array) and basically do the same maths, but with array indexing for the single element being worked on in the current loop.
As a silly example that you should be able to derive from for your example:
a = [1 2 3 4 5];
b = a + 6;
is obviously trivial vectorisation. However if you wanted to be inefficient you could equally do it as:
a = [1 2 3 4 5];
b = zeros( size(A) );
for i = 1:5
b(i) = a(i) + 6;
end
Your question doesn't seem to say you have to use fprintf, it is a function useful for writing formatted data to file. sprintf would be the equivalent to just create a string for display purposes.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2014년 10월 23일

편집:

2014년 10월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by