Please fix my code

to solve y'=t(y.^2-4)
I try like this.
but something was wrong... Amend pls......
clear all
[x,y]=meshgrid(linspace(0,3,100));
u=ones(100);
v=(y.^2-4)*(1/2).*(log(abs(2-y/2+y)).^(1/2));
quiver(x,y,u,v,0.8)
hold on
t=0, w=1;
dt=0.01;
N=1/dt;
for n=1:N
t=t+dt;
w=w+dt*(y.^2-4)*(1/2).*(log(abs(2-y/2+y)).^(1/2));
st=[st t
end
plot(st,sw,'r')
what is wrong?

4 comentarios

Dyuman Joshi
Dyuman Joshi el 16 de Mayo de 2021
Where does your error occur? What is y?
There's a syntax error in the last line of the for loop.
DGM
DGM el 16 de Mayo de 2021
This line is simply incomplete.
st=[st t
if you want to do
st=[st t];
Then st needs to exist first (maybe as just st = [];)
and you're trying to plot sw, which doesn't exist at all. I'm not inclined to guess at the value or meaning of a missing variable.
지원 안
지원 안 el 17 de Mayo de 2021
clear all
[x,y]=meshgrid(linspace(0,3,100));
u=ones(100);
v=(y.^2-4)*(1/2).*(log(abs(2-y/2+y)).^(1/2));
quiver(x,y,u,v,0.8)
hold on
t=0, w=1;
dt=0.01;
N=1/dt;
st=t; sw=w;
for n=1:N
t=t+dt;
w=w+dt*(y.^2-4)*(1/2).*(log(abs(2-y/2+y)).^(1/2));
st=[st t]; sw=[sw w];
end
plot(st,sw,'r')
but something wrong... what's wrong?
DGM
DGM el 17 de Mayo de 2021
What's the error message say?
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
sw=[sw w];
so look at the size of sw and w
>> size(sw)
ans =
1 1
>> size(w)
ans =
100 100
why is sw the size it is? It's initialized as 1. You could initialize it as an empty vector [], but pay attention to the size of w.
w=1;
% ...
sw=w;
why is w the size it is?
[x,y]=meshgrid(linspace(0,3,100));
% ...
w=w+dt*(y.^2-4)*(1/2).*(log(abs(2-y/2+y)).^(1/2));
w is 2D. You're going to figure out how you want to plot these. Once you figure that out, you'll have to figure out how you need to store them. If you need to store all instances of them, you can concatenate them on dim3.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 16 de Mayo de 2021

Comentada:

DGM
el 17 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by