How to code for an equation for numbers of input?

1 回表示 (過去 30 日間)
Khairun Nisa Khamil
Khairun Nisa Khamil 2018 年 2 月 13 日
Hi,
I am new in Matlab.
Would like to know how to code for this problem.
I have this equation
Qc = 2*N*((alpha*I0*Tc)-(0.5*I0*I0*(rho/G))-(k*G*(Th-Tc)))
And i want to compute this equation for I0 from 1 to 10 and Tc from -60 to 240.
I try coding it this way.
//
N= 96;
G = 0.072;
alpha = 0.000203;
rho = 0.001095;
k = 0.01438;
Th = 323;
for I0 = 0.0
for Tc = -60.0
Qc = 2*N*((alpha*I0*Tc)-(0.5*I0*I0*(rho/G))-(k*G*(Th-Tc)))
I0 = I0+1
Tc = Qc+30
if I0>=11 && Tc >=270
end
end
end
But, it only give me 1 answer instead of I need the Qc to give me the output in terms of I(1:10) and Tc (-60:240)
Please help

採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 13 日
N = 96;
G = 0.072;
alpha = 0.000203;
rho = 0.001095;
k = 0.01438;
Th = 323;
[I0, Tc] = ndgrid(1:10, -60:240);
Qc = 2*N*((alpha .* I0 .* Tc) - (0.5 .* I0 .* I0 .* (rho./G)) - (k .* G .* (Th-Tc)));
surf(I0, Tc, Qc, 'edgecolor', 'none')
  4 件のコメント
Walter Roberson
Walter Roberson 2018 年 2 月 14 日
Yes, it is possible. See https://blogs.mathworks.com/graphics/2014/10/21/double_pendulum/ for a more complicated example. I do not think you need to create a class for this, but you should have the general structure of an initialization phase and an update phase.
Khairun Nisa Khamil
Khairun Nisa Khamil 2018 年 2 月 15 日
The example is very complicated for me to understand.
i tried doing it this way using matlab function in simulink.
I used this code
function [y1,y2,y3] = fcn(u)
h = u(1);
deltatmax = u(2);
Imax = u(3);
Umax = u(4);
z0 = (2.*u(2))/((u(1)-u(2))^2);
alphaM = u(4)/u(1);
rhoM = ((u(1)-u(2))*u(4)*u(3))/(2*u(1)*u(2));
kM = ((u(1)-u(2))*u(4))/(u(1)*u(3));
N = 127;
[I0, Tc] = ndgrid(0:10, 300:-20:240);
y1 = ((alphaM .* I0 .* Tc) - (0.5 .* I0 .* I0 .*rhoM) - (kM .*(u(1)-Tc)));
y2 = alphaM.*(u(1)-Tc)+(I0.*rhoM);
y3 = y1./(y2.*I0);
figure (1);
plot (I0,y1);
figure (2);
plot (y2,y1);
But it doesn't give the output i want in workspace.
The results i want is the graph on left but the scope shows result on right. Not sure what i did wrong. Or should i use S Function instead?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by