how to use imported data in matlab equations?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
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
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
let suppose s has values in range of (J2:J100).
i want to find values of x,y,m and z by using data of s which is import from excel.
Dear Walter Reberson:
s values we will import from below excel file and other four unknowns we will find from equations than we plot(x,s).
i need solution of x,y,m and z for each value of s.
than i want to plot(x,s).
Okay, so read the s data in using readtable or xlsread() . And then proceed from just after your code line
s = myData.solar_radiation
but with the change I show here to use arrayfun.
Engineer Batoor khan mummand
2020년 10월 7일
편집: Engineer Batoor khan mummand
2020년 10월 7일
thanks from your reply W.R.
if you give some information about E1,E2,E3 and E4 which yu have written in last comment.
this is my code what should i include ?
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
plot(x,s)
hold on
plot(y,s)
hold on
plot(z,s)
Hi Walter:
the only confusion i have is E1,E2,E3,and E4 in below equation:
[x, y, t, z] = arrayfun(@(E1, E2, E3, E4) vpasolve([E1, E2, E3, E4], [x, y, t, z]), eqn1, eqn2, eqn3, eqn4).
should i put equations instead of E1,E2,E3 and E4 or i should put variables .
thank you so much .
dear Walter:
this is error :
Error using arrayfun
All of the input arguments must be of the same size and shape.
Previous inputs had size 1 in dimension 1. Input #3 has size 2891
Error in neww (line 15)
[x,y,t,z] = arrayfun(@(x,s)vpasolve([s*x+4*y-3*z+12*t-100, 2*x+3*s.*y+4*z+200*t-200, 3*x+y+z+4*s.*t-150,25*x+20*y+10*s.*t-250]), [x, y, t, z],
eqn1, eqn2, eqn3, eqn4)
thanks
E1, E2, E3, E4 are argument names for the anonymous function.
[x, y, z, m] = arrayfun(@(E1, E2, E3, E4) vpasolve([E1, E2, E3, E4], [x, y, z, m]), eqn1, eqn2, eqn3, eqn4);
is nearly the same as:
xout = zeros(size(eqn1), 'sym');
yout = zeros(size(eqn1), 'sym');
zout = zeros(size(eqn1), 'sym');
mout = zeros(size(eqn1), 'sym');
for K = 1 : numel(eqn1)
E1 = eqn1(K);
E2 = eqn2(K);
E3 = eqn3(K);
E4 = eqn4(K);
[xout(K), yout(K), zout(K), mout(K)] = vpasolve([E1, E2, E3, E4], [x, y, z, m]);
end
x = xout; y = yout; z = zout; m = mout;
clear E1 E2 E3 E4 K xout yout zout mout
During execution of the anonymous function, the first parameter passed to the anonymous function is known by the name E1, the second parameter is known by E2, the third parameter is known by E3, the fourth parameter is known as E4. The body of the anonymous function is executed with those values.
E1, E2, E3, E4 have no independent existence: they stand in for "what was passed as the first parameter", "what was passed as the second parameter" and so on.
That approach with vpasolve is just too slow. Here is a much faster version:
if ispc()
filename = 'batorrrkhaan.xlsx';
varname = 'solar_radiation';
else
filename = 'Taxila_TMY1.xlsx';
varname = 'Direct normal Radiation [Wh/m^2]';
end
syms x y m z
myData = readtable(filename, 'Sheet', 'Taxila-hour', 'PreserveVariableNames', true);
s = myData.(varname);
iThreshold = 200;
iKeep = s >= iThreshold;
s = s(iKeep);
syms S
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;
sol = solve([eqn1, eqn2, eqn3, eqn4], [x, y, z, m]);
x = double(subs(sol.x, S, s));
y = double(subs(sol.y, S, s));
z = double(subs(sol.z, S, s));
m = double(subs(sol.m, S, s));
I had to guess about which variable name in the file you posted corresponded to solar radiation.
You will need to adjust the filename and varname for your actual situation.
thank you so much for your concentration :
i will try above code .
Error using readtable (line 198)
Invalid parameter name: PreserveVariableNames.
Error in teching (line 10)
myData = readtable(filename, 'Sheet', 'Taxila-hour', 'PreserveVariableNames', true);
PreserveVariableNames ?
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_'
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개)
카테고리
도움말 센터 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
제품
참고 항목
2020년 10월 7일
2020년 10월 8일
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
