Mathematics / Mathematik / Matemática

Mathematics / Mathematik / Matemática

Posts 1-7 of 7
  • Dr. Matthias Heidrich
    Dr. Matthias Heidrich
    The company name is only visible to registered members.
    Stürzt ab bei Funktionsaufruf
    Hallo, vielleicht kann mir jemand helfen. Ich möchte einen Matlab-Algorithmus implementieren und aus irgendeinem komischen Grund stürzt mein Programm bei der Datenübergabe von Funktionen immer ab.

    Ich poste mal ein Minimal-Beispiel und hoffe es kann mir jemand helfen!

    Gruß Matthias


    Es werden 3 Vektoren e, p und sigma definiert.
    Jeweils 25 elemente lang (spalte).

    m=length(e);
    x0=ones(m,1);

    OUT=objective(x0,e,p,sigma); % Funktionsaufruf, funktioniert auch, nur bei der ergebnisrückgabe stürzt alle ab.
    f=OUT{1}
    g=OUT{2}



    und jetzt noch die Funktion:

    function OUT=objective(x,e,p,sigma)

    CELL=creditrisk(x.*e,p,sigma); %Hier wird ein MEX-FILE ausgewertet. Funktioniert auch gut.

    qw=CELL{1};
    RC=CELL{2};
    sigma_pf=CELL{3};
    my_pf=CELL{4};
    C=CELL{5}; % Die Daten kommen auch alle an


    % **** Nun ein bisschen rechnen. Ist eigentlich egal.....

    g=zeros(length(x),1);
    xi_pf=(qw-my_pf)/sigma_pf;

    for i=1:length(x)
    if x(i)~=0
    g(i)=((-p(i)*e(i))*(xi_pf*sigma_pf)*x(i)-(xi_pf*RC(i)))/(x(i)*(xi_pf*sigma_pf)*(xi_pf*sigma_pf));
    else
    g(i)=((-p(i)*e(i))*(xi_pf*sigma_pf)*x(i)-(xi_pf*RC(i)))/(0.000001*(xi_pf*sigma_pf)*(xi_pf*sigma_pf));
    end
    end

    % Fertig gerechnet - ich kann die Ergebnisse ausgeben und in ein CELL schreiben:

    OUT{1}=qw %Zuweisung Rechenergebnisse an Output-CELL
    OUT{2}=g

    fprintf('objective ende') % Funktioniert auch noch
    This post was modified on 08 Dec 2006 at 10:43 am.
  • Dietrich Brunn
    Dietrich Brunn
    The company name is only visible to registered members.
    Re: Stürzt ab bei Funktionsaufruf
    Hi Matthias,
    nimm mal die Zeile
    fprintf(...
    aus deinem Code. Die ist eigentlich dazu gedacht Daten in eine Datei zu schreiben und benötigt normalerweise eine file handle. Ohne handle macht sie komische Sachen.
    Gruß, dietrich
  • Dr. Matthias Heidrich
    Dr. Matthias Heidrich
    The company name is only visible to registered members.
    Re^2: Stürzt ab bei Funktionsaufruf
    Gute Idee,
    hat aber nichts geändert :-(

    Wenn ich mit Breakpoints arbeite bekomme ich noch folgende Ausgaben:
    (kurz vor Parameterübergabe, OUT wird also vernünftig gesetzt)

    OUT =

    [5.5246e+07]


    OUT =

    [5.5246e+07] [25x1 double]


    Und dann diese Meldung:

    Checked all 26 compact memory blocks. Found no corrupted blocks.

    ------------------------------------------------------------------------
    Assertion detected at Fri Dec 8 12:19:58 2006
    ------------------------------------------------------------------------

    Assertion failed: Forced Assertion at line 591 of file "memmgr/mem32.cpp".
    Attempt to free unaligned pointer


    Configuration:
    MATLAB Version: 7.1.0.21 (R14) Service Pack 3
    MATLAB License: STUDENT
    Operating System: Darwin 7.9.0 Darwin Kernel Version 7.9.0: Wed Mar 30 20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC Power Macintosh
    Window System: The XFree86 Project, Inc (40300000), display :0.0
    Current Visual: 0x22 (class 4, depth 24)
    Virtual Machine: Java 1.4.2_09 with "Apple Computer, Inc." Java HotSpot(TM) Client VM mixed mode
    Default Charset: ISO-8859-1

    Stack Trace:
    [0] libmwbridge.dylib:ThrowAssertion() + 140 bytes
    [1] libmwbridge.dylib:MATLABAssertFcn(char const*, char const*, int, char const*) + 144 bytes
    [2] libut.dylib:mw_free32 + 396 bytes
    [3] libmx.dylib:mxDestroyArrayContents(mxArray_tag*) + 212 bytes
    [4] libmx.dylib:mxDestroyArray + 72 bytes
    [5] libmwm_interpreter.dylib:inResetWS(inWorkSpace_tag*, int) + 180 bytes
    [6] libmwm_interpreter.dylib:std::basic_filebuf<wchar_t, std::char_traits<wchar_t> >::_M_underflow_common(bool) + 194612 bytes
    [7] libmwm_interpreter.dylib:inWordsj + 688 bytes
    [8] libmwm_dispatcher.dylib:Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**) + 344 bytes
    [9] libmwm_interpreter.dylib:inDispatchFromStack + 1620 bytes
    [10] libmwm_interpreter.dylib:inCallFcnFromReference + 308 bytes
    [11] libmwm_interpreter.dylib:inInterp(inDebugCheck, int, int, opcodes, inPcodeNest_tag volatile*, int*) + 5924 bytes
    [12] libmwm_interpreter.dylib:inInterPcodeSJ(inDebugCheck, int, int, opcodes, inPcodeNest_tag*, int*) + 224 bytes
    [13] libmwm_interpreter.dylib:inExecuteMFunctionOrScript(Mfh_mp*, bool) + 784 bytes
    [14] libmwm_interpreter.dylib:inExecCompScript + 480 bytes
    [15] libmwm_dispatcher.dylib:Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**) + 344 bytes
    [16] libmwm_interpreter.dylib:inDispatchFromStack + 1620 bytes
    [17] libmwm_interpreter.dylib:inDispatchCall(char const*, int, int, int, int*, int*) + 216 bytes
    [18] libmwm_interpreter.dylib:inInterp(inDebugCheck, int, int, opcodes, inPcodeNest_tag volatile*, int*) + 5572 bytes
    [19] libmwm_interpreter.dylib:inInterPcodeSJ(inDebugCheck, int, int, opcodes, inPcodeNest_tag*, int*) + 224 bytes
    [20] libmwm_interpreter.dylib:inInterPcode + 84 bytes
    [21] libmwm_interpreter.dylib:in_local_call_eval_function(int*, _pcodeheader*, int*, mxArray_tag**, inDebugCheck) + 168 bytes
    [22] libmwm_interpreter.dylib:inEvalStringWithIsVarFcn(_memory_context*, char const*, EvalType, int, mxArray_tag**, inDebugCheck, _pcodeheader*, int*, bool (*)(void*, char const*), void*) + 2864 bytes
    [23] libmwm_interpreter.dylib:inEvalString + 48 bytes
    [24] libmwm_interpreter.dylib:inEvalCmdWithLocalReturnandtype(char const*, int*, inDebugCheck) + 96 bytes
    [25] libmwbridge.dylib:ThrowSignal(char const*) + 80 bytes
    [26] libmwbridge.dylib:mnParser + 564 bytes
    [27] libmwmcr.dylib:mcrInstance::mnParser() + 104 bytes
    [28] MATLAB:mcrMain(int, char**) + 284 bytes
    [29] MATLAB:run_main(void*) + 24 bytes
    [30] libSystem.B.dylib:0x90024990

    Please follow these steps in reporting this problem to The MathWorks so
    that we have the best chance of correcting it:

    1. Send this crash report to segv@mathworks.com for automated analysis.
    For your convenience, this information has been recorded in:
    /Users/diplom/matlab_crash_dump.3237

    2. Also, if the problem is reproducible, send the crash report to
    support@mathworks.com along with:
    - A specific list of steps that will reproduce the problem
    - Any M, MEX, MDL or other files required to reproduce the problem
    - Any error messages displayed to the command window
    A technical support engineer will contact you with further information.

    Thank you for your assistance. Please save your workspace and restart
    MATLAB before continuing your work.

    Error in ==> OA2 at 172
    OUT=objective(x0,e,p,sigma);


    Und wenn ich jetzt im Debugger noch einen Schritt weiter gehen möchte stürzt Matlab ab. Seufz.


    Matthias
  • Dietrich Brunn
    Dietrich Brunn
    The company name is only visible to registered members.
    Re^3: Stürzt ab bei Funktionsaufruf
    Hi Matthias,
    schade, dass es dies nicht war.
    Meiner Erfahrung stürzt Matlab gerne bei folgenden Sachen ab:
    - Darstellung komplexer 3D Grafiken (oft Bug im OpenGL)
    - Viel Speicher verbrauchen (einige 100 MB)
    - Verwendung externer Funktionen, welche Probleme mit der Speicherverwaltung haben
    Wenn deine Arrays nicht sehr groß sind, tippe ich auf deine MEX-Funktionen.
    Leider kann ich dir keine spezielleren Tipps geben.
    Gruß, dietrich
  • Post visible to registered members
  • Post visible to registered members
  • Dr. Matthias Heidrich
    Dr. Matthias Heidrich
    The company name is only visible to registered members.
    Re^6: Stürzt ab bei Funktionsaufruf
    Vielen Dank an Alle für die Tipps.
    Es lag am Mex-File. Schlichter Speicher-überlauf.

    Nun gehts besser, mal schauen wie es mit großen Beispielen ausschaut :-)

    Gruß
    Matthias