Advertisement
NaroxEG

Solve Eqns

Dec 6th, 2024
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.10 KB | None | 0 0
  1. function solveEqnsBtn_Callback(hObject, eventdata, handles)
  2. % hObject    handle to solveEqnsBtn (see GCBO)
  3. % eventdata  reserved - to be defined in a future version of MATLAB
  4. % handles    structure with handles and user data (see GUIDATA)
  5. aVals = [];
  6. bVals = [];
  7. cVals = [];
  8. dVals = [];
  9. ConstVals = [];
  10. if get(handles.checkbox1, 'Value') == 1
  11.     aVals = [aVals; str2double(get(handles.a1, 'String'))];
  12.     ConstVals = [ConstVals; str2double(get(handles.Const1, 'String'))];
  13. end
  14.  
  15. if get(handles.checkbox2, 'Value') == 1
  16.     aVals = [aVals; str2double(get(handles.a2, 'String'))];
  17.     bVals = [bVals; str2double(get(handles.b1, 'String'))];
  18.     bVals = [bVals; str2double(get(handles.b2, 'String'))];
  19.     ConstVals = [ConstVals; str2double(get(handles.Const2, 'String'))];
  20. end
  21.  
  22. if get(handles.checkbox3, 'Value') == 1
  23.     aVals = [aVals; str2double(get(handles.a3, 'String'))];
  24.     bVals = [bVals; str2double(get(handles.b3, 'String'))];
  25.     cVals = [cVals; str2double(get(handles.c1, 'String'))];
  26.     cVals = [cVals; str2double(get(handles.c2, 'String'))];
  27.     cVals = [cVals; str2double(get(handles.c3, 'String'))];
  28.     ConstVals = [ConstVals; str2double(get(handles.Const3, 'String'))];
  29. end
  30.  
  31. if get(handles.checkbox4, 'Value') == 1
  32.     aVals = [aVals; str2double(get(handles.a4, 'String'))];
  33.     bVals = [bVals; str2double(get(handles.b4, 'String'))];
  34.     cVals = [cVals; str2double(get(handles.c4, 'String'))];
  35.     dVals = [dVals; str2double(get(handles.d1, 'String'))];
  36.     dVals = [dVals; str2double(get(handles.d2, 'String'))];
  37.     dVals = [dVals; str2double(get(handles.d3, 'String'))];
  38.     dVals = [dVals; str2double(get(handles.d4, 'String'))];
  39.     ConstVals = [ConstVals; str2double(get(handles.Const4, 'String'))];
  40. end
  41.  
  42. A = [aVals bVals cVals dVals];
  43. sol = A\ConstVals;
  44. solStr = arrayfun(@(x) sprintf('%.2f', x), sol, 'UniformOutput', false);
  45. while numel(solStr) < 4
  46.     solStr{end+1} = 'N/A';  % Append 'N/A' for missing values
  47. end
  48.  
  49. % Create the result string dynamically
  50. resultTxt = sprintf('X1 = %s\nX2 = %s\nX3 = %s\nX4 = %s\n', solStr{:});
  51. set(handles.text18, 'String', resultTxt)
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement