Method of Newton Rhapson

1 vue (au cours des 30 derniers jours)
Jessé
Jessé le 27 Juil 2015
if true
% code
end a program on the Newton Rhapson method in GUI.
if true
function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 27-Jul-2015 13:52:31
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function xini_Callback(hObject, eventdata, handles)
% hObject handle to xini (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of xini as text
% str2double(get(hObject,'String')) returns contents of xini as a double
% --- Executes during object creation, after setting all properties.
function xini_CreateFcn(hObject, eventdata, handles)
% hObject handle to xini (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function tolerancia_Callback(hObject, eventdata, handles)
% hObject handle to tolerancia (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of tolerancia as text
% str2double(get(hObject,'String')) returns contents of tolerancia as a double
% --- Executes during object creation, after setting all properties.
function tolerancia_CreateFcn(hObject, eventdata, handles)
% hObject handle to tolerancia (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function funcion_Callback(hObject, eventdata, handles)
% hObject handle to funcion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of funcion as text
% str2double(get(hObject,'String')) returns contents of funcion as a double
% --- Executes during object creation, after setting all properties.
function funcion_CreateFcn(hObject, eventdata, handles)
% hObject handle to funcion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function raiz_Callback(hObject, eventdata, handles)
% hObject handle to raiz (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of raiz as text
% str2double(get(hObject,'String')) returns contents of raiz as a double
% --- Executes during object creation, after setting all properties.
function raiz_CreateFcn(hObject, eventdata, handles)
% hObject handle to raiz (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in seleccionar.
function seleccionar_Callback(hObject, eventdata, handles)
% hObject handle to seleccionar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
format long g
f=get(handles.funcion,'string');
xi=get(handles.xini,'string');
Es=get(handles.tolerancia,'string');
xi=str2double(xi);
Es=str2double(Es);
syms x
df=diff(f);
df=inline('df');
ddf=diff(f,2);
ddf=inline('ddf');
f=inline(f);
i=1;
Ea(1)=100;
xi1=x1;
v=get(handles.seleccionar,'value');
switch v
case 2
while abs(Ea>=Es)
fxi=feval(f,xi);
dfxi=feval(df,xi);
xi1= xi -(fxi/dfxi);
Ea=abs((xi1-xi)/(xi1)*100);
xi=xi1;
i=i+1;
end
h=num2str(xi1);
set(handles.raiz,'string',h);
c=str3double(h);
fplot(handles.grafica,f,[(c-5) (c+5)]);
case 3
while abs(Ea>=Es)
fxi=feval(f,xi);
dfxi=feval(df,xi);
ddfxi=feval(ddf,xi);
xi1= xi -((fxi*dfxi)/((dfxi)^2-fxi*ddfxi));
Ea=abs(((xi1-xi)/xi1)*100);
xi=xi1;
i=i+1;
end
h=num2str(xi1);
set(handles.raiz,'string',h);
c=str3double(h);
fplot(handles.grafica,f,[(c-5) (c+5)]);
end
% Hints: contents = cellstr(get(hObject,'String')) returns seleccionar contents as cell array
% contents{get(hObject,'Value')} returns selected item from seleccionar
% --- Executes during object creation, after setting all properties.
function seleccionar_CreateFcn(hObject, eventdata, handles)
% hObject handle to seleccionar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function ayuda_Callback(hObject, eventdata, handles)
% hObject handle to ayuda (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function acercade_Callback(hObject, eventdata, handles)
% hObject handle to acercade (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
acercade
% --------------------------------------------------------------------
function insttrucciones_Callback(hObject, eventdata, handles)
% hObject handle to insttrucciones (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
instrucciones
% --------------------------------------------------------------------
function borrar_Callback(hObject, eventdata, handles)
% hObject handle to borrar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.funcion,'string','');
set(handles.xini,'string','');
set(handles.tolerancia,'string','');
set(handles.raiz,'string','');
set(handles.advertir,'string','');
% --------------------------------------------------------------------
function salir_Callback(hObject, eventdata, handles)
% hObject handle to salir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close
Error:
??? Error using ==> feval
Undefined function or method 'pushbutton1_CreateFcn' for input
arguments of type 'double'.
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> untitled at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)untitled('pushbutton1_CreateFcn',hObject,eventdata,guidata(hObject))
??? Error using ==> struct2handle
Error while evaluating uicontrol CreateFcn
??? Error using ==> function seleccionar_CreateFcn(hObject,
eventdata, handles)
Error: Function definitions are not permitted at the prompt or
in scripts.
??? Error using ==> struct2handle
Error while evaluating uipanel CreateFcn
I need for it to calculate this equation .
sqrt(5*x+2)-x
and automatic calculate the derivative.
end
  1 commentaire
Muthu Annamalai
Muthu Annamalai le 27 Juil 2015
Please use the {} Code button to format your code, and ask the question.
Taking time to rewrite this question may actually mean someone will be able to answer you or solve your problem.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 27 Juil 2015
You renamed some of your callbacks by editing the code, but you did not change the Callback properties of the figure. You need to go in with the property inspector and change the strings associated with the Callback for the various parts of the figure such as the pushbutton.

Plus de réponses (2)

sabik EL YATIM
sabik EL YATIM le 15 Juil 2019
Modifié(e) : sabik EL YATIM le 15 Juil 2019
hello I have probleme in this codage I will someone advice me , I will result some equation by methode newton -rapshon and I don't have the good idea
  4 commentaires
sabik EL YATIM
sabik EL YATIM le 16 Juil 2019
thank you my friend, I want to ask you, when I compile the program there are two things Hvt and Hvis becomes imaginary, it is that you can help me
Walter Roberson
Walter Roberson le 16 Juil 2019
Prair=10^-4*(-2.54*Tf)*0.7147;
if((Reair<2300)&&(Prair==0.7)) %ecoulemen laminaire
It is unlikely that Prair will ever become bit-for-bit identical to what MATLAB converts the literal 0.7 into, which is to say the value 0.6999999999999999555910790149937383830547332763671875 exactly.
elseif((2300<Reair<10^6)&&(0.5<=Prair<=1.5)&&(0<(Dh)<1)) % ecoulement transitoire
In that expression, Reair and Prair and Dh are all data type double().
In MATLAB, for numeric values (can be different sometimes for symbolic values), the expression
A < B < C
means the same thing as
((A<B) < C)
The first subexpression, A<B, evaluates to the logical value false or true. In numeric expressions, false is converted to 0 and true is converted to 1, so the (A<B) part will result in the numeric values 0 or 1. That value 0 or 1 is then compared to C.
MATLAB does not have a range test (except sometimes for symbolic expressions.) If you want to test that B is greater than A and less than C, then use A<B & B < C
A=L*2*delta_f;
The first time around, A is assigned a scalar.
A=jacobian([Fv;Fc;Fted;Flui;Fis],[Tv Tc Tt Tf Tis]);
At the end of the loop, A is assigned a 5 x 5 symbolic array.
Reair=(Mdeb*Dh)/(A*Uair);
The first time around, this is okay because A is a scalar. But the second time around, you have a scalar double on the left side of the / operator, and in the denominator, you have (5 x 5 sym) * (1 x 1sym) which gives you a 5 x 5 sym on the right side of the / operator. However, the / operator is "matrix right divide", with P / Q being approximately the same as P * inv(Q) but the number of columns on the two sides have to be equal, so with A*Uair being 5 x 5, (Mdeb*Dh) would have to have 5 columns. You should consider whether perhaps you want the ./ operator instead of the / operator.
else((0.6<=Prair<=160)&&(Reair>6000)&&((L/Dh)>=10)) % ecoulement turbulant
Note that that is the same as
else
disp(((0.6<=Prair<=160)&&(Reair>6000)&&((L/Dh)>=10))) % ecoulement turbulant
because else does not expect a test at that point. If you want that branch to be executed conditionally then use elseif instead of else -- and watch out for the possibility that none of the tests match.
Tv=25+273;
Tc=25+273;
Tt=25+273;
Tf=25+273;
Tis=25+273;
So those are all scalars originally
syms Tv Tc Tt Tf Tis;
but you replace them with symbolic variables. The "clear all" you had after that would have erase (nearly) everything so you have to delete the "clear all" . But if you do, then Tv, Tc, and so on, will have their symbolic variable values when you loop back up. And if you specifically clear those variables to prevent that, then when you loop back up, the variables will not have their original numeric values when you loop back up.
You should avoid using the same variable name as both symbolic and numeric: it is much too common that you will run into these kinds of problems when you do that. Instead you should subs() numeric values in for symbolic names.

Connectez-vous pour commenter.


sabik EL YATIM
sabik EL YATIM le 17 Juil 2019
Error in goal2 (line 155)
if((Reair<2300)&&(Prair==0.7)) %ecoulemen laminaire
Hi, I do not understand why this error is displayed and I find the number Nu and Hvt, Hvis are complex

Community Treasure Hunt

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

Start Hunting!

Translated by