I'm having trouble with my function working with an electrical field problem:
I have my code inserted below, but don't seem to understand how to do the second half of the problem by. Any help would be great. Thank You.
Main Code:
Q = linspace(1,12,12); %sec
r = linspace(0.05,0.6,12); %meter
Q = linspace(1,14,14); %sec
r = linspace(0.76,0.89,14); %meter
Q_t1 = linspace(1.3,1.5,12);
Q_t2 = linspace(1.3,1.7,14); %This is for the second half
[E] = E_sphere(r, Q);
%[E] = E_sphere(r, Q); %This is for the second half
subplot(1,2,1)
plot(E,Q_t1)
subplot(1,2,2)
plot(E,Q_t2)
Function Code:
function [E] = E_sphere(r,Q)
e_o = 8.85e-12; %F/m
E = (Q)/4.*pi.*e_o.*r.*(Q).^2;
end

 채택된 답변

Geoff Hayes
Geoff Hayes 2017년 2월 13일
편집: Geoff Hayes 2017년 2월 13일

0 개 추천

Jim - it isn't clear why you are overwriting your r and Q for the first half with that from the second half. Try keeping your local variables distinct as
Q1 = linspace(1.3,1.5,12); %sec
r1 = linspace(0.05,0.6,12); %meter
Q2 = linspace(1.3,1.7,14); %sec
r2 = linspace(0.76,0.89,14); %meter
Then call your function twice as
E1 = E_sphere(r1,Q1);
E2 = E_sphere(r2,Q2);
The inputs to your function do not have to be named r and Q. Likewise, the output does not have to be named E. They can be named however you want but you do want the names to be relevant or specific to their purpose. In this case, I have just added a 1 or 2 to the end of each to indicate that the inputs and results are from data set 1 or 2.
Also, note how the Q's are initialized as per the problem description.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

Jim
2017년 2월 13일

편집:

2017년 2월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by