how to use imported data in matlab equations?

1 次查看(过去 30 天)
Hi to everyone:
i have four equations and four unknowns which is given below:
s*x+4y-3z+12m=100
2x+3*s*y+4z+200m=200
3x+y+z+4*s*m=150
25x+20y+10*s*m=250
where x,y,m znd z is unknown and s is given in excel sheet .
i want to find above unknowns by using s data which is given in excel sheet and than plot(x,s):
i have written code in matlab but it gave me error:
clc;
close all;
clear all;
syms x y m z
myData = readtable('batorrrkhaan.xlsx','Sheet','Taxila-hour')
s = myData.solar_radiation
iThreshold = 200
iKeep = s >= iThreshold
s = s(iKeep)
eqn1=s.*x+4*y-3*z+12*m==100;
eqn2=2*x+3*s.*y+4*z+200*m==200;
eqn3=3*x+y+z+4*s.*m==150;
eqn4=25*x+20*y+10*s.*m==250;
[x,y,t,z]=vpasolve([eqn1, eqn2, eqn3,eqn4],[x,y,t,z]);
x
y
t
z
error is :
z =
Empty sym: 0-by-1
x=
Empty sym: 0-by-1
m=
Empty sym: 0-by-1
y=
Empty sym: 0-by-1

采纳的回答

Walter Roberson
Walter Roberson 2020-10-7
eqn1=s.*x+4*y-3*z+12*m==100;
That does not define one equation: it defines one equation for each value of s.
[x,y,t,z]=vpasolve([eqn1, eqn2, eqn3,eqn4],[x,y,t,z]);
That is length(s) times 4 equations being solved for 4 variables. There are no scalar values of x, y, t, z that are able to satisfy all of the equations simultaneously.
solve() does not know that you mean that you want to solve for x, y, z, t per s value. Using one row of equations per s value will not help: solve() treats the set of equations as if you had done reshape(equations, [], 1)
You need to separate the equations yourself.
[x, y, t, z] = arrayfun(@(E1, E2, E3, E4) vpasolve([E1, E2, E3, E4], [x, y, t, z]), eqn1, eqn2, eqn3, eqn4)
  13 个评论
Walter Roberson
Walter Roberson 2020-10-8
Either you have a broken MATLAB installation or else you forgot to tell us that you using an old release of MATLAB.
Remove the 'PreserveVariableNames', true option from the call. You may need to adjust the name in the 'varname' assignment, such as to 'DiffuseHorizontalRadiation_Wh_m_2_'
Engineer Batoor khan mummand
thanks you so much Dear Walter reberson:
i have no words about you , you have solved my problem.
once again thank you so much .

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by