fprintf to plot error

조회 수: 3 (최근 30일)
Edinson Manga
Edinson Manga 2020년 5월 28일
댓글: Walter Roberson 2020년 5월 28일
I need convert fprintf of y0 to vector for plot (x,y0)
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2020년 5월 28일
Edinson - what exactly is your question? Is there a problem with the fprintf? Please claridy. Also, please don't post a screen shot of your code...attach the code or copy and paste it into your question.

댓글을 달려면 로그인하십시오.

답변 (2개)

Edinson Manga
Edinson Manga 2020년 5월 28일
clear all close all clc
f=@(x,y)2*(2*sin(x)+cos(x))-5*sin(x); %Write your f(x,y) function, where dy/dx=f(x,y), x(x0)=y0. x0=0; %example x0=0 y0=1; %example y0=0.5 xn=4;% where we need to find the value of y %example x=2 h=0.05; %example h=0.2 %Formula: k1=h*f(x0,y0); k2=h*f(x0+h,y0+k1); y1=y0+(k1+k2)/2; fprintf('\n x y '); while x0<=xn i=0; fprintf('\n%4.3f %4.3f ',x0,y0); %values of x and y k1=h*f(x0,y0); x1=x0+h; k2=h*f(x1,y0+k1); y1=y0+(k1+k2)/2 ; x0=x1 y0=y1; i=i+1; x=0:0.05:4
end
  댓글 수: 2
Edinson Manga
Edinson Manga 2020년 5월 28일
the problem is that I have no idea how I can pass the different y0 that fprintf throws a cumulative vector in order to graph
Walter Roberson
Walter Roberson 2020년 5월 28일
That should have been posted as a Comment to your Question.
When you edit it in up there, first press the ">" button in the CODE section of the editor toolbar, and then paste your nicely indented code into the area that creates, so that it gets post as formatted code.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2020년 5월 28일
See https://www.mathworks.com/matlabcentral/answers/534868-make-matrix-with-loop#answer_439778 for a general code outline that you should probably use.
Question: why do you change x each iteration of the loop? You do not use x in the loop.
Why are you initializing i in the loop and then incrementing it (so each loop you set it to zero and then set it to one.) You are not using i anywhere. If you want to know how many iterations it takes you should not be setting i to 0 each time.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by