writing a formula dependant on time
Show older comments
I'm trying to write a simple formula for the following code:
if true
%variables
H0=10;
w=(2*pi)/12.25;
Qm1=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
Qm2=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
Qm12=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
t=0.5:0.5:24;
A1=101364;
A2=A1;
tau=0.5;
rho=1029;
N=0.8;
g=9.81;
H1(1)=10;
H2(1)=0;
d1=1;
d2=0;
d3=0;
%Heads
%Ocean
Hm=H0*(cos(w*t));
%Basin1
H1(t)=(H1*(t-tau))-((Qm1/A1)*tau)+((Qm12/A1)*tau);
%Basin2
%H2(t)=H2*(t-tau)+(Qm2/A2)*tau-(Qm12/A2)*tau;
%Power
P1=N*rho*(Hm-H1)*Qm1*d1;
P2=N*rho*g*(Hm-H2)*Qm2*d2;
%P3=N*rho*g*(Hm-H12)*Qm12*d3;
P=P1+P2+P3;
end
P1,P2 and P3 fail since that Matlab recognises I'm trying to multiply two 1x48 matrices. Hm and H1 are fine, however Q1 and Q2 should represent different values throughout a daily cycle (48 values for 48 half hours in a day). So should I end with 48 values for P1 P2 and P3 each. What I'm trying to write is a formula for P(t) and for Matlab to repeat the formula 48 times to show me how it changes through the day.
I'm also not sure my code for H11 is right. It should represent an instantaneous value:
if true
H1(t)=(H1*(t-tau))-((Qm1/A1)*tau)+((Qm12/A1)*tau)
end
So H1 is equal to the value of H1 the half hour before minus the value for Qm1/A1 for that instance multiplied by tau, which is half an hour. The Q values will eventually be populated by values once I know the code is working
I would appreciate an answer as to how I would code this correctly and I apologise for the unclear explanation. Please ask any questions and I'll answer to the best of my ability.
3 Comments
Explorer
on 23 Feb 2016
If you have a phone with camera, capture the photo of formula you want to code up and upload it here.
Star Strider
on 23 Feb 2016
This a duplicate of your previous Question: http://www.mathworks.com/matlabcentral/answers/269463-how-do-i-solve-inner-matrix-must-agree-in-this-question. The same observations and comments apply here.
Go through your code to find the reason one of your vectors is 97 elements long and the other is 48 elements long.
I cannot determine what you want your code to do, and what result you want from it in either your previous Question or this one.
Harley Fraser
on 23 Feb 2016
Answers (1)
Jos (10584)
on 23 Feb 2016
Use element wise operators (.* and ./) rather than matrix operators (* and /)
A = magic(2)
A*A
A.*A
A/A
A./A
1 Comment
Harley Fraser
on 23 Feb 2016
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!